PHP7.4 New Features 新特性

- Core:

? . Added support for typed properties. For example:

? ? ? ? class User {

? ? ? ? ? ? public int $id;

? ? ? ? ? ? public string $name;

? ? ? ? }

? ? This will enforce that $user->id can only be assigned integer and

? ? $user->name can only be assigned strings. For more information see the

? ? RFC: https://wiki.php.net/rfc/typed_properties_v2

? . Added support for arrow functions with implicit by-value scope binding.

? ? For example:

? ? ? ? $factor = 10;

? ? ? ? $nums = array_map(fn($num) => $num * $factor, $nums);

? ? RFC: https://wiki.php.net/rfc/arrow_functions_v2

? . Added support for limited return type covariance and argument type

? ? contravariance. The following code will now work:

? ? ? ? class A {}

? ? ? ? class B extends A {}

? ? ? ? class Producer {

? ? ? ? ? ? public function method(): A {}

? ? ? ? }

? ? ? ? class ChildProducer extends Producer {

? ? ? ? ? ? public function method(): B {}

? ? ? ? }

? ? Full variance support is only available if autoloading is used. Inside a

? ? single file only non-cyclic type references are possible, because all

? ? classes need to be available before they are referenced.

? ? RFC: https://wiki.php.net/rfc/covariant-returns-and-contravariant-parameters

? . Added support for coalesce assign (??=) operator. For example:

? ? ? ? $array['key'] ??= computeDefault();

? ? ? ? // is roughly equivalent to

? ? ? ? if (!isset($array['key'])) {

? ? ? ? ? ? $array['key'] = computeDefault();

? ? ? ? }

? ? RFC: https://wiki.php.net/rfc/null_coalesce_equal_operator

? . Added support for unpacking inside arrays. For example:

? ? ? ? $arr1 = [3, 4];

? ? ? ? $arr2 = [1, 2, ...$arr1, 5];

? ? ? ? // $arr2 == [1, 2, 3, 4, 5]

? ? RFC: https://wiki.php.net/rfc/spread_operator_for_array

? . Support for WeakReferences has been added.

? ? RFC: https://wiki.php.net/rfc/weakrefs

? . Throwing exceptions from __toString() is now permitted. Previously this

? ? resulted in a fatal error. Existing recoverable fatals in string conversions

? ? have been converted to Error exceptions.

? ? RFC: https://wiki.php.net/rfc/tostring_exceptions

- CURL:

? . CURLFile now supports stream wrappers in addition to plain file names, if

? ? the extension has been built against libcurl >= 7.56.0.? The streams may

? ? need to be seekable.

- Filter:

? . The FILTER_VALIDATE_FLOAT filter now supports the min_range and max_range

? ? options, with the same semantics as FILTER_VALIDATE_INT.

- FFI:

? . A new extension which provides a simple way to call native functions, access

? ? native variables and create/access data structures defined in C libraries.

? ? RFC: https://wiki.php.net/rfc/ffi

- GD:

? . Added the "scatter" image filter (IMG_FILTER_SCATTER) to apply a scatter

? ? filter to images. This filter has the following prototype:

? ? ? ? imagefilter($im, IMG_FILTER_SCATTER, int $sub, int $plus, array $colors = []);

? ? The $colors array can be populated with a set of indexed colors where to

? ? apply the scatter pixel shifting on.

? ? Note, the result of this filter is always random.

- Hash:

? . Added "crc32c" hash using Castagnoli's polynomial. This crc32 variant is

? ? used by storage systems, such as iSCSI, SCTP, Btrfs and ext4.

- Mbstring:

? . Added mb_str_split() function, which provide the same functionality as

? ? str_split(), but operating on code points rather than bytes.

? ? RFC: https://wiki.php.net/rfc/mb_str_split

- OPcache:

? . Support for preloading code has been added.

? ? RFC: https://wiki.php.net/rfc/preload

- PCRE:

? . The preg_replace_callback() and preg_replace_callback_array() functions now

? ? accept an additional $flags argument, with support for the

? ? PREG_OFFSET_CAPTURE and PREG_UNMATCHED_AS_NULL flags. This influences the

? ? format of the matches array passed to to the callback function.

- PDO_OCI:

? . PDOStatement::getColumnMeta() is now available

- PDO_SQLite:

? . PDOStatement::getAttribute(PDO::SQLITE_ATTR_READONLY_STATEMENT) allows to

? ? check whether this statement is read-only, i.e. whether it doesn't modify

? ? the database.

- Standard:

? . strip_tags() now also accepts an array of allowed tags: Instead of

? ? strip_tags($str, '<a><p>') you can now write strip_tags($str, ['a', 'p']).

? . A new mechanism for custom object serialization has been added, which

? ? uses two new magic methods:

? ? ? ? // Returns array containing all the necessary state of the object.

? ? ? ? public function __serialize(): array;

? ? ? ? // Restores the object state from the given data array.

? ? ? ? public function __unserialize(array $data): void;

? ? The new serialization mechanism supersedes the Serializable interface,

? ? which will be deprecated in the future.

? ? RFC: https://wiki.php.net/rfc/custom_object_serialization

? . array_merge() and array_merge_recursive() may now be called without any

? ? arguments, in which case they will return an empty array. This is useful

? ? in conjunction with the spread operator, e.g. array_merge(...$arrays).

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市拷窜,隨后出現(xiàn)的幾起案子澳盐,更是在濱河造成了極大的恐慌明垢,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,657評論 6 505
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件跃脊,死亡現(xiàn)場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機狭瞎,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,889評論 3 394
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來搏予,“玉大人熊锭,你說我怎么就攤上這事⊙┙模” “怎么了碗殷?”我有些...
    開封第一講書人閱讀 164,057評論 0 354
  • 文/不壞的土叔 我叫張陵,是天一觀的道長速缨。 經(jīng)常有香客問我锌妻,道長,這世上最難降的妖魔是什么旬牲? 我笑而不...
    開封第一講書人閱讀 58,509評論 1 293
  • 正文 為了忘掉前任仿粹,我火速辦了婚禮,結(jié)果婚禮上原茅,老公的妹妹穿的比我還像新娘吭历。我一直安慰自己,他們只是感情好擂橘,可當我...
    茶點故事閱讀 67,562評論 6 392
  • 文/花漫 我一把揭開白布晌区。 她就那樣靜靜地躺著,像睡著了一般通贞。 火紅的嫁衣襯著肌膚如雪朗若。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,443評論 1 302
  • 那天昌罩,我揣著相機與錄音哭懈,去河邊找鬼。 笑死茎用,一個胖子當著我的面吹牛银伟,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播绘搞,決...
    沈念sama閱讀 40,251評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼彤避,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了夯辖?” 一聲冷哼從身側(cè)響起琉预,我...
    開封第一講書人閱讀 39,129評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎蒿褂,沒想到半個月后圆米,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體卒暂,經(jīng)...
    沈念sama閱讀 45,561評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,779評論 3 335
  • 正文 我和宋清朗相戀三年娄帖,在試婚紗的時候發(fā)現(xiàn)自己被綠了也祠。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,902評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡近速,死狀恐怖诈嘿,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情削葱,我是刑警寧澤奖亚,帶...
    沈念sama閱讀 35,621評論 5 345
  • 正文 年R本政府宣布,位于F島的核電站析砸,受9級特大地震影響昔字,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜首繁,卻給世界環(huán)境...
    茶點故事閱讀 41,220評論 3 328
  • 文/蒙蒙 一作郭、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧弦疮,春花似錦夹攒、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,838評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽堂湖。三九已至闲先,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間无蜂,已是汗流浹背伺糠。 一陣腳步聲響...
    開封第一講書人閱讀 32,971評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留斥季,地道東北人训桶。 一個月前我還...
    沈念sama閱讀 48,025評論 2 370
  • 正文 我出身青樓,卻偏偏與公主長得像酣倾,于是被迫代替她去往敵國和親舵揭。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 44,843評論 2 354