// iterable 伪类(与 callable 类似) interfaceTraversableextendsiterable{ // 这个接口没有任何方法,它的作用仅仅是作为所有可遍历类的基本接口 // Traversable as part of either Iterator or IteratorAggregate,不能直接实现 }
// 当传递参数过少时将抛出错误 functiontest($param){} test(); /* PHP71 Fatal error: Uncaught ArgumentCountError: Too few arguments to function test() PHP70 Warning: Missing argument 1 for test() */
$a = 0; call_user_func('increment', $a); // ...expected to be a reference, value given call_user_func_array('increment', [&$a]); // 1 $increment = 'increment'; $increment($a); // 2
// 词法绑定变量不能重用名称,以下都将 fatal error $f = function () use ($_SERVER) {}; // any superglobals $f = function () use ($this) {}; $f = function ($param) use ($param) {};
// 禁止 "return;" 对于已经在编译时键入的返回值 functiontest(int$i): array { $i += 1; return; } // PHP Compile Error A function with return type must return a value
var_dump('1b' + 'something'); /* PHP71 Notice: A non well formed numeric value encountered Warning: A non-numeric value encountered int(1) PHP70 int(1) */
// 柯里化 functionadd($a) { returnfunction($b) use ($a) { return$a + $b; }; } $result = add(10)(15); var_dump($result); // int 25
Deprecated features in PHP 7.0.x
// 构造函数(方法名和类名一样)将被弃用,并在将来移除 classFoo{ functionfoo() { echo'I am the constructor'; } } // PHP 7.0: Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP // PHP 5.6: OK