PHP 7.4 in 7 code blocks

栏目: IT技术 · 发布时间: 5年前

内容简介:PHP 7.4, the last edition in the 7.* series, brings lots of new and handy changes. This post lists the highlights, though there's much more to this release. You can read all about the full release in this post aboutArrow functions, a.k.a. short closures.Ty

PHP 7.4, the last edition in the 7.* series, brings lots of new and handy changes. This post lists the highlights, though there's much more to this release. You can read all about the full release in this post about what's new in PHP 7.4 .

array_map(
    fn(User $user) => $user->id,
    $users
);

Arrow functions, a.k.a. short closures.

class A
{
    public string $name;
    
    public ?Foo $foo;
}

Type properties. There's quite a lot to tellabout them.

$data['date'] ??= new DateTime();

The null coalescing assignment operator.

class ParentType {}
class ChildType extends ParentType {}

class A
{
    public function covariantReturnTypes(): ParentType
    { /* … */ }
}

class B extends A
{
    public function covariantReturnTypes(): ChildType
    { /* … */ }
}

Improved type variance. If you're not sure what that's about, you should take a look at this post about Liskov and type safety .

$result = [...$arrayA, ...$arrayB];

The array spread operator.

$formattedNumber = 107_925_284.88;

The numeric literal separator.

[preloading]
opcache.preload=/path/to/project/preload.php

Preloading improves PHP performance across requests.

There's even more. If you want a full list, you can find iton this blog. What 7.4 feature do you like the most? Let me know on Twitter or viaemail.


以上所述就是小编给大家介绍的《PHP 7.4 in 7 code blocks》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

编码

编码

查尔斯•佩措尔德 (Charles Petzold) / 左飞、薛佟佟 / 电子工业出版社 / 2012-10-1 / 59.00元

编码:隐匿在计算机软硬件背后的语言,ISBN:9787121181184,作者:(美)佩措尔德(Petzold,C.)著 左飞,薛佟佟译一起来看看 《编码》 这本书的介绍吧!

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具