Rumah > Artikel > pembangunan bahagian belakang > PHP 7.0 升级备注,php7.0升级备注_PHP教程
PHP 7.0.0 beta1 发布了,在带来了引人注目的性能提升的同时,也带来了不少语言特性方面的改变。以下由 LCTT 翻译自对官方的升级备注,虽然目前还不是正式发布版,不过想必距离正式发布的特性已经差别不大了。(本文会持续追踪更新)
间接变量、属性和方法引用现在以从左到右的语义进行解释。一些例子:
<span class="pln">$$foo<span class="pun">[<span class="str">'bar'<span class="pun">][<span class="str">'baz'<span class="pun">]<span class="pln"> <span class="com">// 解释做 ($$foo)['bar']['baz'] </span></span></span></span></span></span></span></span>
<span class="pln">$foo<span class="pun">-><span class="pln">$bar<span class="pun">[<span class="str">'baz'<span class="pun">]<span class="pln"> <span class="com">// 解释做 ($foo->$bar)['baz']</span></span></span></span></span></span></span></span>
<span class="pln">$foo<span class="pun">-><span class="pln">$bar<span class="pun">[<span class="str">'baz'<span class="pun">]()<span class="pln"> <span class="com">// 解释做 ($foo->$bar)['baz']()</span></span></span></span></span></span></span></span>
<span class="typ">Foo<span class="pun">::<span class="pln">$bar<span class="pun">[<span class="str">'baz'<span class="pun">]()<span class="pln"> <span class="com">// 解释做 (Foo::$bar)['baz']()</span></span></span></span></span></span></span></span>
要恢复以前的行为,需要显式地加大括号:
<span class="pln">$<span class="pun">{<span class="pln">$foo<span class="pun">[<span class="str">'bar'<span class="pun">][<span class="str">'baz'<span class="pun">]}</span></span></span></span></span></span></span></span>
<span class="pln">$foo<span class="pun">->{<span class="pln">$bar<span class="pun">[<span class="str">'baz'<span class="pun">]}</span></span></span></span></span></span>
<span class="pln">$foo<span class="pun">->{<span class="pln">$bar<span class="pun">[<span class="str">'baz'<span class="pun">]}()</span></span></span></span></span></span>
<span class="typ">Foo<span class="pun">::{<span class="pln">$bar<span class="pun">[<span class="str">'baz'<span class="pun">]}()</span></span></span></span></span></span>
全局关键字现在只接受简单变量。像以前的
<span class="kwd">global<span class="pln"> $$foo<span class="pun">-><span class="pln">bar<span class="pun">;</span></span></span></span></span>
现在要求如下写法:
<span class="kwd">global<span class="pln"> $<span class="pun">{<span class="pln">$foo<span class="pun">-><span class="pln">bar<span class="pun">};</span></span></span></span></span></span></span>
变量或函数调用的前后加上括号不再有任何影响。例如下列代码,函数调用结果以引用的方式传给一个函数
<span class="kwd">function<span class="pln"> getArray<span class="pun">()<span class="pln"> <span class="pun">{<span class="pln"> <span class="kwd">return<span class="pln"> <span class="pun">[<span class="lit">1<span class="pun">,<span class="pln"> <span class="lit">2<span class="pun">,<span class="pln"> <span class="lit">3<span class="pun">];<span class="pln"> <span class="pun">}</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>
<span class="pln">$last <span class="pun">=<span class="pln"> array_pop<span class="pun">(<span class="pln">getArray<span class="pun">());</span></span></span></span></span></span>
<span class="com">// Strict Standards: 只有变量可以用引用方式传递</span>
<span class="pln">$last <span class="pun">=<span class="pln"> array_pop<span class="pun">((<span class="pln">getArray<span class="pun">()));</span></span></span></span></span></span>
<span class="com">// Strict Standards: 只有变量可以用引用方式传递</span>
现在无论是否使用括号,都会抛出一个严格标准错误。以前在第二种调用方式下不会有提示。
数组元素或对象属性自动安装引用顺序创建,现在的结果顺序将不同。例如:
<span class="pln">$array <span class="pun">=<span class="pln"> <span class="pun">[];</span></span></span></span>
<span class="pln">$array<span class="pun">[<span class="str">"a"<span class="pun">]<span class="pln"> <span class="pun">=&<span class="pln"> $array<span class="pun">[<span class="str">"b"<span class="pun">];</span></span></span></span></span></span></span></span></span></span>
<span class="pln">$array<span class="pun">[<span class="str">"b"<span class="pun">]<span class="pln"> <span class="pun">=<span class="pln"> <span class="lit">1<span class="pun">;</span></span></span></span></span></span></span></span></span>
<span class="pln">var_dump<span class="pun">(<span class="pln">$array<span class="pun">);</span></span></span></span>
现在结果是 ["a" => 1, "b" => 1],而以前的结果是 ["b" => 1, "a" => 1]。
相关的 RFC:
list() 不再以反序赋值,例如:
<span class="pln">list<span class="pun">(<span class="pln">$array<span class="pun">[],<span class="pln"> $array<span class="pun">[],<span class="pln"> $array<span class="pun">[])<span class="pln"> <span class="pun">=<span class="pln"> <span class="pun">[<span class="lit">1<span class="pun">,<span class="pln"> <span class="lit">2<span class="pun">,<span class="pln"> <span class="lit">3<span class="pun">];</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>
<span class="pln">var_dump<span class="pun">(<span class="pln">$array<span class="pun">);</span></span></span></span>
现在结果是 $array == [1, 2, 3] ,而不是 [3, 2, 1]。注意仅赋值顺序变化了,而赋值仍然一致(LCTT 译注:即以前的 list()行为是从后面的变量开始逐一赋值,这样对与上述用法就会产生 [3,2,1] 这样的结果了。)。例如,类似如下的常规用法
<span class="pln">list<span class="pun">(<span class="pln">$a<span class="pun">,<span class="pln"> $b<span class="pun">,<span class="pln"> $c<span class="pun">)<span class="pln"> <span class="pun">=<span class="pln"> <span class="pun">[<span class="lit">1<span class="pun">,<span class="pln"> <span class="lit">2<span class="pun">,<span class="pln"> <span class="lit">3<span class="pun">];</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>
<span class="com">// $a = 1; $b = 2; $c = 3;</span>
仍然保持当前的行为。
不再允许对空的 list() 赋值。如下全是无效的:
<span class="pln">list<span class="pun">()<span class="pln"> <span class="pun">=<span class="pln"> $a<span class="pun">;</span></span></span></span></span></span>
<span class="pln">list<span class="pun">(,,)<span class="pln"> <span class="pun">=<span class="pln"> $a<span class="pun">;</span></span></span></span></span></span>
<span class="pln">list<span class="pun">(<span class="pln">$x<span class="pun">,<span class="pln"> list<span class="pun">(),<span class="pln"> $y<span class="pun">)<span class="pln"> <span class="pun">=<span class="pln"> $a<span class="pun">;</span></span></span></span></span></span></span></span></span></span></span></span>
list() 不再支持对字符串的拆分(以前也只在某些情况下支持)。如下代码:
<span class="pln">$string <span class="pun">=<span class="pln"> <span class="str">"xy"<span class="pun">;</span></span></span></span></span>
<span class="pln">list<span class="pun">(<span class="pln">$x<span class="pun">,<span class="pln"> $y<span class="pun">)<span class="pln"> <span class="pun">=<span class="pln"> $string<span class="pun">;</span></span></span></span></span></span></span></span></span></span>
现在的结果是: $x == null 和 $y == null (没有提示),而以前的结果是: $x == "x" 和 $y == "y" 。此外, list() 现在总是可以处理实现了 ArrayAccess 的对象,例如:
<span class="pln">list<span class="pun">(<span class="pln">$a<span class="pun">,<span class="pln"> $b<span class="pun">)<span class="pln"> <span class="pun">=<span class="pln"> <span class="pun">(<span class="kwd">object<span class="pun">)<span class="pln"> <span class="kwd">new<span class="pln"> <span class="typ">ArrayObject<span class="pun">([<span class="lit">0<span class="pun">,<span class="pln"> <span class="lit">1<span class="pun">]);</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>
现在的结果是: $a == 0 和 $b == 1。 以前 $a 和 $b 都是 null。
相关 RFC:
foreach() 迭代不再影响数组内部指针,数组指针可通过 current()/next() 等系列的函数访问。例如:
<span class="pln">$array <span class="pun">=<span class="pln"> <span class="pun">[<span class="lit">0<span class="pun">,<span class="pln"> <span class="lit">1<span class="pun">,<span class="pln"> <span class="lit">2<span class="pun">];</span></span></span></span></span></span></span></span></span></span></span></span>
<span class="kwd">foreach<span class="pln"> <span class="pun">(<span class="pln">$array <span class="kwd">as<span class="pln"> <span class="pun">&<span class="pln">$val<span class="pun">)<span class="pln"> <span class="pun">{</span></span></span></span></span></span></span></span></span></span></span>
<span class="pln"> var_dump<span class="pun">(<span class="pln">current<span class="pun">(<span class="pln">$array<span class="pun">));</span></span></span></span></span></span>
<span class="pun">}</span>
现在将指向值 int(0) 三次。以前的输出是 int(1)、int(2) 和 bool(false)。
在对数组按值迭代时,foreach 总是在对数组副本进行操作,在迭代中任何对数组的操作都不会影响到迭代行为。例如:
<span class="pln">$array <span class="pun">=<span class="pln"> <span class="pun">[<span class="lit">0<span class="pun">,<span class="pln"> <span class="lit">1<span class="pun">,<span class="pln"> <span class="lit">2<span class="pun">];</span></span></span></span></span></span></span></span></span></span></span></span>
<span class="pln">$ref <span class="pun">=&<span class="pln"> $array<span class="pun">;<span class="pln"> <span class="com">// Necessary to trigger the old behavior</span></span></span></span></span></span>
<span class="kwd">foreach<span class="pln"> <span class="pun">(<span class="pln">$array <span class="kwd">as<span class="pln"> $val<span class="pun">)<span class="pln"> <span class="pun">{</span></span></span></span></span></span></span></span></span>
<span class="pln"> var_dump<span class="pun">(<span class="pln">$val<span class="pun">);</span></span></span></span>
<span class="pln"> unset<span class="pun">(<span class="pln">$array<span class="pun">[<span class="lit">1<span class="pun">]);</span></span></span></span></span></span>
<span class="pun">}</span>
现在将打印出全部三个元素 (0 1 2),而以前第二个元素 1 会跳过 (0 2)。
在对数组按引用迭代时,对数组的修改将继续会影响到迭代。不过,现在 PHP 在使用数字作为键时可以更好的维护数组内的位置。例如,在按引用迭代过程中添加数组元素:
<span class="pln">$array <span class="pun">=<span class="pln"> <span class="pun">[<span class="lit">0<span class="pun">];</span></span></span></span></span></span>
<span class="kwd">foreach<span class="pln"> <span class="pun">(<span class="pln">$array <span class="kwd">as<span class="pln"> <span class="pun">&<span class="pln">$val<span class="pun">)<span class="pln"> <span class="pun">{</span></span></span></span></span></span></span></span></span></span></span>
<span class="pln"> var_dump<span class="pun">(<span class="pln">$val<span class="pun">);</span></span></span></span>
<span class="pln"> $array<span class="pun">[<span class="lit">1<span class="pun">]<span class="pln"> <span class="pun">=<span class="pln"> <span class="lit">1<span class="pun">;</span></span></span></span></span></span></span></span></span>
<span class="pun">}</span>
现在迭代会正确的添加了元素。如上代码输出是 "int(0) int(1)",而以前只是 "int(0)"。
对普通(不可遍历的)对象按值或按引用迭代的行为类似于对数组进行按引用迭代。这符合以前的行为,除了如上一点所述的更精确的位置管理的改进。
对可遍历对象的迭代行为保持不变。
相关 RFC: https://wiki.php.net/rfc/php7_foreach
不能定义两个同名的函数参数。例如,下面的方法将会触发编译时错误:
<span class="kwd">public<span class="pln"> <span class="kwd">function<span class="pln"> foo<span class="pun">(<span class="pln">$a<span class="pun">,<span class="pln"> $b<span class="pun">,<span class="pln"> $unused<span class="pun">,<span class="pln"> $unused<span class="pun">)<span class="pln"> <span class="pun">{</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>
<span class="pln"> <span class="com">// ...</span></span>
<span class="pun">}</span>
如上的代码应该修改使用不同的参数名,如:
<span class="kwd">public<span class="pln"> <span class="kwd">function<span class="pln"> foo<span class="pun">(<span class="pln">$a<span class="pun">,<span class="pln"> $b<span class="pun">,<span class="pln"> $unused1<span class="pun">,<span class="pln"> $unused2<span class="pun">)<span class="pln"> <span class="pun">{</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>
<span class="pln"> <span class="com">// ...</span></span>
<span class="pun">}</span>
func_get_arg() 和 func_get_args() 函数不再返回传递给参数的原始值,而是返回其当前值(也许会被修改)。例如:
<span class="kwd">function<span class="pln"> foo<span class="pun">(<span class="pln">$x<span class="pun">)<span class="pln"> <span class="pun">{</span></span></span></span></span></span></span>
<span class="pln"> $x<span class="pun">++;</span></span>
<span class="pln"> var_dump<span class="pun">(<span class="pln">func_get_arg<span class="pun">(<span class="lit">0<span class="pun">));</span></span></span></span></span></span>
<span class="pun">}</span>
<span class="pln">foo<span class="pun">(<span class="lit">1<span class="pun">);</span></span></span></span>
将会打印 "2" 而不是 "1"。代码应该改成仅在调用 func_get_arg(s) 后进行修改操作。
<span class="kwd">function<span class="pln"> foo<span class="pun">(<span class="pln">$x<span class="pun">)<span class="pln"> <span class="pun">{</span></span></span></span></span></span></span>
<span class="pln"> var_dump<span class="pun">(<span class="pln">func_get_arg<span class="pun">(<span class="lit">0<span class="pun">));</span></span></span></span></span></span>
<span class="pln"> $x<span class="pun">++;</span></span>
<span class="pun">}</span>
或者应该避免修改参数:
<span class="kwd">function<span class="pln"> foo<span class="pun">(<span class="pln">$x<span class="pun">)<span class="pln"> <span class="pun">{</span></span></span></span></span></span></span>
<span class="pln"> $newX <span class="pun">=<span class="pln"> $x <span class="pun">+<span class="pln"> <span class="lit">1<span class="pun">;</span></span></span></span></span></span></span>
<span class="pln"> var_dump<span class="pun">(<span class="pln">func_get_arg<span class="pun">(<span class="lit">0<span class="pun">));</span></span></span></span></span></span>
<span class="pun">}</span>
类似的,异常回溯也不再显示传递给函数的原始值,而是修改后的值。例如:
<span class="kwd">function<span class="pln"> foo<span class="pun">(<span class="pln">$x<span class="pun">)<span class="pln"> <span class="pun">{</span></span></span></span></span></span></span>
<span class="pln"> $x <span class="pun">=<span class="pln"> <span class="lit">42<span class="pun">;</span></span></span></span></span>
<span class="pln"> <span class="kwd">throw<span class="pln"> <span class="kwd">new<span class="pln"> <span class="typ">Exception<span class="pun">;</span></span></span></span></span></span></span>
<span class="pun">}</span>
<span class="pln">foo<span class="pun">(<span class="str">"string"<span class="pun">);</span></span></span></span>
现在堆栈跟踪的结果是:
<span class="typ">Stack<span class="pln"> trace<span class="pun">:</span></span></span>
<span class="com">#0 file.php(4): foo(42)</span>
<span class="com">#1 {main}</span>
而以前是:
<span class="typ">Stack<span class="pln"> trace<span class="pun">:</span></span></span>
<span class="com">#0 file.php(4): foo('string')</span>
<span class="com">#1 {main}</span>
这并不会影响到你的代码的运行时行为,值得注意的是在调试时会有所不同。
同样的限制也会影响到 debug_backtrace() 及其它检查函数参数的函数。
相关 RFC: https://wiki.php.net/phpng
无效的八进制表示(包含大于7的数字)现在会产生编译错误。例如,下列代码不再有效:
<span class="pln">$i <span class="pun">=<span class="pln"> <span class="lit">0781<span class="pun">;<span class="pln"> <span class="com">// 8 不是一个有效的八进制数字!</span></span></span></span></span></span></span>
以前,无效的数字(以及无效数字后的任何数字)会简单的忽略。以前如上 $i 的值是 7,因为后两位数字会被悄悄丢弃。
二进制以负数镜像位移现在会抛出一个算术错误:
<span class="pln">var_dump<span class="pun">(<span class="lit">1<span class="pln"> <span class="pun">>><span class="pln"> <span class="pun">-<span class="lit">1<span class="pun">);</span></span></span></span></span></span></span></span></span>
<span class="com">// ArithmeticError: 以负数进行位移</span>
向左位移的位数超出了整型宽度时,结果总是 0。
<span class="pln">var_dump<span class="pun">(<span class="lit">1<span class="pln"> <span class="pun"> <span class="lit">64<span class="pun">);<span class="pln"> <span class="com">// int(0)</span></span></span></span></span></span></span></span></span>
以前上述代码的结果依赖于所用的 CPU 架构。例如,在 x86(包括 x86-64) 上结果是 int(1),因为其位移操作数在范围内。
类似的,向右位移的位数超出了整型宽度时,其结果总是 0 或 -1 (依赖于符号):
<span class="pln">var_dump<span class="pun">(<span class="lit">1<span class="pln"> <span class="pun">>><span class="pln"> <span class="lit">64<span class="pun">);<span class="pln"> <span class="com">// int(0)</span></span></span></span></span></span></span></span></span></span>
<span class="pln">var_dump<span class="pun">(-<span class="lit">1<span class="pln"> <span class="pun">>><span class="pln"> <span class="lit">64<span class="pun">);<span class="pln"> <span class="com">// int(-1)</span></span></span></span></span></span></span></span></span></span>
相关 RFC: https://wiki.php.net/rfc/integer_semantics
包含十六进制数字的字符串不会再被当做数字,也不会被特殊处理。参见例子中的新行为:
<span class="pln">var_dump<span class="pun">(<span class="str">"0x123"<span class="pln"> <span class="pun">==<span class="pln"> <span class="str">"291"<span class="pun">);<span class="pln"> <span class="com">// bool(false) (以前是 true)</span></span></span></span></span></span></span></span></span></span>
<span class="pln">var_dump<span class="pun">(<span class="pln">is_numeric<span class="pun">(<span class="str">"0x123"<span class="pun">));<span class="pln"> <span class="com">// bool(false) (以前是 true)</span></span></span></span></span></span></span></span>
<span class="pln">var_dump<span class="pun">(<span class="str">"0xe"<span class="pln"> <span class="pun">+<span class="pln"> <span class="str">"0x1"<span class="pun">);<span class="pln"> <span class="com">// int(0) (以前是 16)</span></span></span></span></span></span></span></span></span></span>
<span class="pln">var_dump<span class="pun">(<span class="pln">substr<span class="pun">(<span class="str">"foo"<span class="pun">,<span class="pln"> <span class="str">"0x1"<span class="pun">));<span class="pln"> <span class="com">// string(3) "foo" (以前是 "oo")</span></span></span></span></span></span></span></span></span></span></span>
<span class="com">// 注意:遇到了一个非正常格式的数字</span>
filter_var() 可以用来检查一个字符串是否包含了十六进制数字,或这个字符串是否能转换为整数:
<span class="pln">$str <span class="pun">=<span class="pln"> <span class="str">"0xffff"<span class="pun">;</span></span></span></span></span>
<span class="pln">$int <span class="pun">=<span class="pln"> filter_var<span class="pun">(<span class="pln">$str<span class="pun">,<span class="pln"> FILTER_VALIDATE_INT<span class="pun">,<span class="pln"> FILTER_FLAG_ALLOW_HEX<span class="pun">);</span></span></span></span></span></span></span></span></span></span>
<span class="kwd">if<span class="pln"> <span class="pun">(<span class="kwd">false<span class="pln"> <span class="pun">===<span class="pln"> $int<span class="pun">)<span class="pln"> <span class="pun">{</span></span></span></span></span></span></span></span></span></span>
<span class="pln"> <span class="kwd">throw<span class="pln"> <span class="kwd">new<span class="pln"> <span class="typ">Exception<span class="pun">(<span class="str">"Invalid integer!"<span class="pun">);</span></span></span></span></span></span></span></span></span>
<span class="pun">}</span>
<span class="pln">var_dump<span class="pun">(<span class="pln">$int<span class="pun">);<span class="pln"> <span class="com">// int(65535)</span></span></span></span></span></span>
由于给双引号字符串和 HERE 文档增加了 Unicode 码点转义格式(Unicode Codepoint Escape Syntax), 所以带有无效序列的 "\u{" 现在会造成错误:
<span class="pln">$str <span class="pun">=<span class="pln"> <span class="str">"\u{xyz}"<span class="pun">;<span class="pln"> <span class="com">// 致命错误:无效的 UTF-8 码点转义序列</span></span></span></span></span></span></span>
要避免这种情况,需要转义开头的反斜杠:
<span class="pln">$str <span class="pun">=<span class="pln"> <span class="str">"\\u{xyz}"<span class="pun">;<span class="pln"> <span class="com">// 正确</span></span></span></span></span></span></span>
不过,不跟随 { 的 "\u" 不受影响。如下代码不会生成错误,和前面的一样工作:
<span class="pln">$str <span class="pun">=<span class="pln"> <span class="str">"\u202e"<span class="pun">;<span class="pln"> <span class="com">// 正确</span></span></span></span></span></span></span>
相关 RFC:
现在有两个异常类: Exception 和 Error 。这两个类都实现了一个新接口: Throwable 。在异常处理代码中的类型指示也许需要修改来处理这种情况。
一些致命错误和可恢复的致命错误现在改为抛出一个 Error 。由于 Error 是一个独立于 Exception 的类,这些异常不会被已有的 try/catch 块捕获。
可恢复的致命错误被转换为一个异常,所以它们不能在错误处理里面悄悄的忽略。部分情况下,类型指示失败不再能忽略。
解析错误现在会生成一个 Error 扩展的 ParseError 。除了以前的基于返回值 / errorgetlast() 的处理,对某些可能无效的代码的 eval() 的错误处理应该改为捕获 ParseError 。
内部类的构造函数在失败时总是会抛出一个异常。以前一些构造函数会返回 NULL 或一个不可用的对象。
一些 E_STRICT 提示的错误级别改变了。
相关 RFC:
静态调用一个不兼容的 $this 上下文的非静态调用的做法不再支持。这种情况下,$this 是没有定义的,但是对它的调用是允许的,并带有一个废弃提示。例子:
<span class="kwd">class<span class="pln"> A <span class="pun">{</span></span></span>
public function test() { var_dump($this); <span class="pun">}</span>
<span class="pun">}</span>
<span class="com">// 注意:没有从类 A 进行扩展</span>
<span class="kwd">class<span class="pln"> B <span class="pun">{</span></span></span>
public function callNonStaticMethodOfA() { A::test(); <span class="pun">}</span>
<span class="pun">}</span>
<span class="pun">(<span class="kwd">new<span class="pln"> B<span class="pun">)-><span class="pln">callNonStaticMethodOfA<span class="pun">();</span></span></span></span></span></span>
<span class="com">// 废弃:非静态方法 A::test() 不应该被静态调用</span>
<span class="com">// 提示:未定义的变量 $this</span>
<span class="pln">NULL</span>
注意,这仅出现在来自不兼容上下文的调用上。如果类 B 扩展自类 A ,调用会被允许,没有任何提示。
不能使用下列类名、接口名和特殊名(大小写敏感):
<span class="kwd">bool</span>
<span class="kwd">int</span>
<span class="kwd">float</span>
<span class="kwd">string</span>
<span class="kwd">null</span>
<span class="kwd">false</span>
<span class="kwd">true</span>
这用于 class/interface/trait 声明、 class_alias() 和 use 语句中。
此外,下列类名、接口名和特殊名保留做将来使用,但是使用时尚不会抛出错误:
<span class="pln">resource</span>
<span class="kwd">object</span>
<span class="pln">mixed</span>
<span class="pln">numeric</span>
yield 语句结构当用在一个表达式上下文时,不再要求括号。它现在是一个优先级在 “print” 和 “=>” 之间的右结合操作符。在某些情况下这会导致不同的行为,例如:
<span class="pln">echo <span class="kwd">yield<span class="pln"> <span class="pun">-<span class="lit">1<span class="pun">;</span></span></span></span></span></span>
<span class="com">// 以前被解释如下</span>
<span class="pln">echo <span class="pun">(<span class="kwd">yield<span class="pun">)<span class="pln"> <span class="pun">-<span class="pln"> <span class="lit">1<span class="pun">;</span></span></span></span></span></span></span></span></span>
<span class="com">// 现在被解释如下</span>
<span class="pln">echo <span class="kwd">yield<span class="pln"> <span class="pun">(-<span class="lit">1<span class="pun">);</span></span></span></span></span></span>
<span class="kwd">yield<span class="pln"> $foo <span class="kwd">or<span class="pln"> <span class="kwd">die<span class="pun">;</span></span></span></span></span></span>
<span class="com">// 以前被解释如下</span>
<span class="kwd">yield<span class="pln"> <span class="pun">(<span class="pln">$foo <span class="kwd">or<span class="pln"> <span class="kwd">die<span class="pun">);</span></span></span></span></span></span></span></span>
<span class="com">// 现在被解释如下</span>
<span class="pun">(<span class="kwd">yield<span class="pln"> $foo<span class="pun">)<span class="pln"> <span class="kwd">or<span class="pln"> <span class="kwd">die<span class="pun">;</span></span></span></span></span></span></span></span></span>
这种情况可以通过增加括号来解决。
移除了 ASP () 标签。
RFC: https://wiki.php.net/rfc/remove_alternative_php_tags
不支持以引用的方式对 new 的结果赋值。
不支持对一个来自非兼容的 $this 上下文的非静态方法的域内调用。细节参见: https://wiki.php.net/rfc/incompat_ctx 。
不支持 ini 文件中的 # 风格的备注。使用 ; 风格的备注替代。
$HTTP_RAW_POST_DATA 不再可用,使用 php://input 流替代。
call_user_method() 和 call_user_method_array() 不再存在。
在一个输出缓冲区被创建在输出缓冲处理器里时, ob_start() 不再发出 E_ERROR,而是 E_RECOVERABLE_ERROR。
改进的 zend_qsort (使用 hybrid 排序算法)性能更好,并改名为 zend_sort。
增加静态排序算法 zend_insert_sort。
移除 fpm-fcgi 的 dl() 函数。
setcookie() 如果 cookie 名为空会触发一个 WARNING ,而不是发出一个空的 set-cookie 头。
Curl:
Date:
DBA
GMP
Intl:
libxml:
Mcrypt
Session
Opcache
OpenSSL:
PCRE:
PDO_pgsql:
Standard:
JSON:
Stream:
XSL:
Core
Opcache
OpenSSL
Reflection
Stream
Core
OpenSSL
parse_ini_string():
unserialize():
proc_open():
array_column():
stream_context_create()
GMP
PCRE:
Standard . 添加了整数除法 intdiv() 函数。 . 添加了重置错误状态的 error_clear_last() 函数。
Zlib: . 添加了 deflate_init()、 deflate_add()、 inflate_init()、 inflate_add() 函数来运行递增和流的压缩/解压。
(暂无)
更多细节参见:
注意:NSAPI 没有在 RFC 中投票,不过它会在以后移除。这就是说,它相关的 SDK 今后不可用。
Core . 添加 PHP_INT_MIN
Zlib
GD
函数:
资源:
Core
ftp
odbc