内容简介:PHP 7.4.0 发布了,此版本标志着 PHP 7 系列的第四次特性更新。 PHP 7.4.0 进行了许多改进,并带来了一些新特性,包括: Typed Properties 类型属性 类属性现在支持类型声明,以下示例将强制 $User-> id 只能分配...
PHP 7.4.0 发布了,此版本标志着 PHP 7 系列的第四次特性更新。
PHP 7.4.0 进行了许多改进,并带来了一些新特性,包括:
Typed Properties 类型属性
类属性现在支持类型声明,以下示例将强制 $User-> id 只能分配 int 值,而 $User-> name 只能分配 string 值。
<?php
class User {
public int $id;
public string $name;
}
?>
Arrow Functions 箭头函数
箭头函数提供了用于定义具有隐式按值作用域绑定的函数的简写语法。
<?php
$factor = 10;
$nums = array_map(fn($n) => $n * $factor, [1, 2, 3, 4]);
// $nums = array(10, 20, 30, 40);
?>
将闭包传递给 array_map 或 array_filter 等函数时,它可以发挥极大的作用。
// A collection of Post objects $posts = [/* … */];
$ids = array_map(fn($post) => $post->id, $posts);
Limited Return Type Covariance and Argument Type Contravariance 有限返回类型协变与参数类型逆变
仅当使用自动加载时,才提供完全协变/逆变支持。在单个文件中,只能使用非循环类型引用,因为所有类在被引用之前都必须可用。
<?php
class A {}
class B extends A {}
class Producer {
public function method(): A {}
}
class ChildProducer extends Producer {
public function method(): B {}
}
?>
Unpacking Inside Arrays 打包内部数组
<?php
$parts = ['apple', 'pear'];
$fruits = ['banana', 'orange', ...$parts, 'watermelon'];
// ['banana', 'orange', 'apple', 'pear', 'watermelon'];
?>
Numeric Literal Separator 数值文字分隔符
数字文字可以在数字之间包含下划线。
<?php
6.674_083e-11; // float
299_792_458; // decimal
0xCAFE_F00D; // hexadecimal
0b0101_1111; // binary
?>
Weak References 弱引用
弱引用使 程序员 可以保留对对象的引用,不会阻止对象被销毁。
Allow Exceptions from __toString() 允许从 __toString() 抛出异常
现在允许从 __toString() 引发异常,以往这会导致致命错误,字符串转换中现有的可恢复致命错误已转换为 Error 异常。
Opcache Preloading Opcache 预加载
新增 Opcache 预加载支持。
此外还有一些弃用,以及从核心中删除一些扩展,详情查看:
以上所述就是小编给大家介绍的《PHP 7.4.0 发布》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- NPM包(模块)发布、更新、撤销发布
- 有赞灰度发布与蓝绿发布实践
- 【重磅发布】Linkis 0.10.0 版本发布
- BeetlSQL 3.0.9 发布,Idea 插件发布
- 贝密游戏 0.7.0 发布,发布斗地主
- 【重磅发布】DataSphere Studio 0.9.0 版本发布
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Data Structures and Algorithms
Alfred V. Aho、Jeffrey D. Ullman、John E. Hopcroft / Addison Wesley / 1983-1-11 / USD 74.20
The authors' treatment of data structures in Data Structures and Algorithms is unified by an informal notion of "abstract data types," allowing readers to compare different implementations of the same......一起来看看 《Data Structures and Algorithms》 这本书的介绍吧!