Home > Article > Backend Development > PHP 7.0 upgrade notes, php7.0 upgrade notes_PHP tutorial
PHP 7.0.0 beta1 has been released, which not only brings eye-catching performance improvements, but also brings Many language feature changes. The following is translated by LCTT from the official upgrade notes. Although it is not an official release version yet, it is presumably not much different from the officially released features. (This article will continue to be tracked and updated)
Indirect variable, property and method references are now interpreted with left-to-right semantics. Some examples:
<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>
To restore the previous behavior, explicitly add braces:
<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>
Global keywords now only accept simple variables. Like before
<span class="kwd">global<span class="pln"> $$foo<span class="pun">-><span class="pln">bar<span class="pun">;</span></span></span></span></span>
Now the following writing method is required:
<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>
Placing parentheses around variables or function calls no longer has any effect. For example, in the following code, the function call result is passed to a function by reference
<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>
Now throws a strict standard error whether or not parentheses are used. Previously there was no prompt in the second calling method.
Array elements or object properties are automatically created in reference order and the resulting order will now be different. For example:
<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>
Now the result is ["a" => 1, "b" => 1], while the previous result was ["b" => 1, "a" => 1].
Related RFCs:
list() no longer assigns values in reverse order, for example:
<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>
Now the result is $array == [1, 2, 3] instead of [3, 2, 1]. Note that only the assignment order has changed, but the assignment is still the same (LCTT translation annotation: that is, the previous list() behavior was to assign values one by one starting from the following variables, so that the above usage will produce [3,2, 1] This is the result. For example, common usage like the following
<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>
Still maintains current behavior.
Assignment to an empty list() is no longer allowed. The following are all invalid:
<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() no longer supports splitting strings (it used to be supported only in certain circumstances). The following code:
<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>
The result now is: $x == null and $y == null (without prompt), whereas before the result was: $x == "x" and $y == "y" . Additionally, list() can now always handle objects that implement ArrayAccess, for example:
<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>
The result now is: $a == 0 and $b == 1. Previously $a and $b were both null.
Related RFC:
foreach() iteration no longer affects the internal pointer of the array, and the array pointer can be accessed through current()/next() and other series of functions. For example:
<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>
will now point to the value int(0) three times. Previous output was int(1), int(2), and bool(false).
When iterating an array by value, foreach always operates on a copy of the array, and any operations on the array during iteration will not affect the iteration behavior. For example:
<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>
All three elements (0 1 2) will now be printed, whereas previously the second element 1 would be skipped (0 2).
When iterating over an array by reference, modifications to the array will continue to affect the iteration. However, PHP now maintains better positioning within arrays when using numbers as keys. For example, adding array elements during by-reference iteration:
<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>
Iteration now correctly adds elements. The output of the above code is "int(0) int(1)", whereas before it was just "int(0)".
Iteration by value or by reference over a normal (non-traversable) object behaves like iteration by reference over an array. This is in line with previous behavior, except for improvements to more precise location management as mentioned in the previous point.
The behavior of iteration over traversable objects remains unchanged.
Related RFC: https://wiki.php.net/rfc/php7_foreach
Cannot define two function parameters with the same name. For example, the following method will trigger a compile-time error:
<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>
The above code should be modified to use different parameter names, such as:
<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>
The func_get_arg() and func_get_args() functions no longer return the original value passed to the argument, but instead return its current value (perhaps modified). For example:
<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>
will print "2" instead of "1". The code should be changed to modify only after calling 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>
Or modification of parameters should be avoided:
<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>
Similarly, the exception traceback no longer displays the original value passed to the function, but the modified value. For example:
<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>
Now the stack trace is:
<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>
Whereas it used to be:
<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>
This does not affect the runtime behavior of your code, it is worth noting that it will be different when debugging.
The same limitation also affects debug_backtrace() and other functions that check function parameters.
Related RFC: https://wiki.php.net/phpng
Invalid octal representation (containing numbers greater than 7) now produces a compilation error. For example, the following code no longer works:
<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>
Previously, invalid numbers (and any numbers after the invalid number) were simply ignored. Previously the value of $i above was 7 because the last two digits were silently discarded.
Binary mirroring displacements with negative numbers now throws an arithmetic error:
<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>
When the number of bits shifted to the left exceeds the width of the integer, the result is always 0.
<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>
The results of the previous code depended on the CPU architecture used. For example, on x86 (including x86-64) the result is int(1) because its shift operand is in range.
Similarly, shifting to the right by more than the width of the integer always results in 0 or -1 (depending on the sign):
<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>
Related RFC: https://wiki.php.net/rfc/integer_semantics
Strings containing hexadecimal digits will no longer be treated as numbers, nor will they be treated specially. See the new behavior in the example:
<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() can be used to check whether a string contains hexadecimal digits, or whether the string can be converted to an integer:
<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>
Due to the addition of Unicode Codepoint Escape Syntax to double-quoted strings and HERE documents, "u{" with an invalid sequence now causes an error:
<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>
To avoid this, escape the leading backslash:
<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>
However, "u" not followed by { is not affected. The following code will not generate an error and works the same as the previous one:
<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>
Related RFC:
There are now two exception classes: Exception and Error . Both classes implement a new interface: Throwable. Type directives in exception handling code may need to be modified to handle this situation.
Some fatal and recoverable fatal errors now throw an Error instead. Since Error is a separate class from Exception, these exceptions will not be caught by existing try/catch blocks.
Recoverable fatal errors are converted into an exception, so they cannot be silently ignored in error handling. Type indication failures can no longer be ignored in some cases.
Parse errors now generate an Error extended ParseError . In addition to the previous return value/errorgetlast() based handling, error handling of eval() for some potentially invalid code should instead catch ParseError .
Constructors of inner classes always throw an exception on failure. Previously some constructors would return NULL or an unavailable object.
The error levels of some E_STRICT prompts have been changed.
Related RFC:
Static calling a non-static call with an incompatible $this context is no longer supported. In this case, $this is undefined, but calls to it are allowed with a deprecation hint. Example:
<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>
Note that this only occurs on calls from incompatible contexts. If class B extends from class A, the call will be allowed without any prompts.
The following class names, interface names and special names (case sensitive) cannot be used:
<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>
This is used in class/interface/trait declarations, class_alias() and use statements.
In addition, the following class names, interface names, and special names are reserved for future use, but will not throw an error when used:
<span class="pln">resource</span>
<span class="kwd">object</span>
<span class="pln">mixed</span>
<span class="pln">numeric</span>
yield statement structure no longer requires parentheses when used in the context of an expression. It is now a right-associative operator with precedence between "print" and "=>". This can lead to different behavior in some cases, for example:
<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>
This situation can be solved by adding parentheses.
Removed ASP (<%) and script (