PHP 7.4 in 7 code blocks

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

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

查看所有标签

猜你喜欢:

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

众声喧哗

众声喧哗

胡泳 / 广西师范大学出版社 / 2008-9 / 35.00元

本书触及了网络政治学中的一个重大话题——网络空间中的私域与公域。随着科技的进步,在信息时代的开端,公与私的含义和边界都出现了不容忽视的游移。《众声喧哗》主要探讨,经由新的共有媒体的作用,传统的公私两分如何在社会和政治的双重压力下产生消长和易位。在这里,公域与私域不能看做结构性的东西,而必须视之为一种流和一种过程。在网络时代,我们既要追求生机勃勃的公共生活,又要保证私人领域一定的自主性。共有媒体也许......一起来看看 《众声喧哗》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

URL 编码/解码
URL 编码/解码

URL 编码/解码

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具