PHP各版本之间差异

PHP5.3

__toString 魔术方法不再接受参数.

魔术方法 __get, __set, __isset, __unset, and __call 应该总是公共的(public)且不能是静态的(static). 方法签名是必须的.

添加了命名空间的支持

增加了goto支持。

新增了两个魔术方法, __callStatic 和 __invoke.

随着匿名函数的加入,PHP 引入了一个新的魔术方法 __invoke().
该魔术方法会在将一个对象作为函数调用时被调用:

class A
{
    public function __invoke($str)
    {
        print "A::__invoke(): {$str}";
    }
}

$a = new A;
$a("Hello World");
输出毫无疑问是:  A::__invoke(): Hello World

__callStatic() 则会在调用一个不存在的静态方法时被调用。

添加了 Nowdoc 语法支持, 类似于 Heredoc 语法, 但是包含单引号.就是<<'EOF'这样的语法。

可在类外部使用 const 关键词声明 常量.

三元运算操作符有了简写形式: ?:

PHP5.4

新增traits关键字,使PHP类可以实现多继承

新增短数组语法,比如 a=[1,2,3,4];a=[1,2,3,4];或a = ['one' => 1, 'two' => 2, 'three' => 3, 'four' => 4]; 

新增支持对函数返回数组的成员访问解析,例如 foo()[0] 。

现在不管是否设置 short_open_tag php.ini 选项,<?= 将总是可用。

新增在实例化时访问类成员,例如: (new Foo)->bar() 。

SESSION 扩展现在能追踪文件的 上传进度 。

内置用于开发的 CLI 模式的 web server 。

PHP5.5

新增Finally关键字:http://www.laruence.com/2012/08/16/2709.html

新赠yield关键字,可以在方法中返回多个值所组成的数组

<?php
function gen_one_to_three() {
    for ($i = 1; $i <= 3; $i++) {
        // Note that $i is preserved between yields.
        yield $i;
    }
}

$generator = gen_one_to_three();
foreach ($generator as $value) {
    echo "$value
";
}
?> 

 增加了opcache扩展

PHP5.6

PHP7

原文地址:https://www.cnblogs.com/linux-centos/p/5413515.html