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》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

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

Essential C++中文版

Essential C++中文版

[美] Stanley B. Lippman / 侯捷 / 华中科技大学出版社 / 2001-8 / 39.80元

书中以4个面向来表现C++的本质:procedural(程序性的)、generic(泛型的)、object-based(个别对象的)、object-oriented(面向对象的),全书围绕着一系列逐渐繁复的程序问题,以及用以解决这些问题的语言特性。循此方式,读者不只学到C++的函数和结构,也会学习到它们的设计目的和基本原理。一起来看看 《Essential C++中文版》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具

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

HEX CMYK 互转工具