略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: 新特性

2024-04-20

新特性

PHP 5.4.0 提供了丰富的新特性:

  • 新增支持 traits
  • 新增短数组语法,比如 $a = [1, 2, 3, 4];$a = ['one' => 1, 'two' => 2, 'three' => 3, 'four' => 4];
  • 新增支持对函数返回数组的成员访问解析,例如 foo()[0]
  • 现在 闭包 支持 $this
  • 现在不管是否设置 short_open_tag php.ini 选项,<?= 将总是可用。
  • 新增在实例化时访问类成员,例如: (new Foo)->bar()
  • 现在支持 Class::{expr}() 语法。
  • 新增二进制直接量,例如:0b001001101
  • 改进解析错误信息和不兼容参数的警告。
  • SESSION 扩展现在能追踪文件的 上传进度
  • 内置用于开发的 CLI 模式的 web server
add a note add a note

User Contributed Notes 3 notes

up
30
Nick Garvey
6 years ago
'callable' was implemented as a typehint in 5.4
up
2
Joris Berthelot
11 months ago
PHP 5.4 also allows to use arrays in switch:

<?php

$foo
= 1;
$bar = 2;

switch([
$foo, $bar]) {
    case [
1, 2]:
        echo
'case 1';
        break;
    case [
2, 2]:
        echo
'case 2';
        break;
    case [
3, 4]:
        echo
'case 3';
        break;
}

// Will output  "case 1"
?>
up
11
dave1010 at gmail dot com
6 years ago
As of PHP 5.4, the CLI (using readline) no longer dies on fatal errors (for example calling undefined functions).

官方地址:https://www.php.net/manual/en/migration54.new-features.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3