PHP Velho Oeste 2024

新特性

PHP 5.3.0 提供了广泛的新特性:

  • 添加了 命名空间 的支持.
  • 添加了 静态晚绑定 支持.
  • 添加了 跳转标签 (limited goto) 支持。
  • 添加了原生的 闭包 (Lambda/匿名函数) 支持.
  • 新增了两个魔术方法, __callStatic__invoke
  • 添加了 Nowdoc 语法支持,类似于 Heredoc 语法,但是包含单引号。
  • 使用 Heredoc 来初始化静态变量和类属性/常量变为可能。
  • 可使用双引号声明 Heredoc,补充了 Nowdoc 语法。
  • 可在类外部使用 const 关键词声明 常量
  • 三元运算 操作符有了简写形式:?:
  • HTTP 流包裹器将从 200 到 399 全部的状态码都视为成功。
  • 动态访问静态方法变为可能。
    <?php
    class {
       public static 
    $foo 123;
    }

    $a "C";
    echo 
    $a::$foo;
    ?>

    以上例程会输出:

    123
    
  • 异常可以被内嵌:
    <?php
    class MyCustomException extends Exception {}

    try {
        throw new 
    MyCustomException("Exceptional"112);
    } catch (
    Exception $e) {
        
    /* Note the use of the third parameter to pass $e
         * into the RuntimeException. */
        
    throw new RuntimeException("Rethrowing"911$e);
    }
    ?>
  • 新增了循环引用的 垃圾回收器 并且默认是开启的。
  • mail() 现在支持邮件发送日志,需要通过 mail.log 配置。(注意: 仅支持通过该函数发送的邮件)。
add a note add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top