mirror of
https://github.com/php/php-src.git
synced 2024-09-30 06:16:08 +00:00
80748631aa
If yield is used in an expression context parenthesis are now required. This ensures that the code is unambiguos. Yield statements can still be used without parenthesis (which should be the most common case). Also yield expressions without value can be used without parenthesis, too (this should be the most common case for coroutines). If the yield expression is used in a context where parenthesis are required anyway, no additional parenthesis have to be inserted. Examples: // Statements don't need parenthesis yield $foo; yield $foo => $bar; // Yield without value doesn't need parenthesis either $data = yield; // Parentheses don't have to be duplicated foo(yield $bar); if (yield $bar) { ... } // But we have to use parentheses here $foo = (yield $bar); This commit also fixes an issue with by-ref passing of $foo[0] like variables. They previously weren't properly fetched for write. Additionally this fixes valgrind warnings which were caused by access to uninitialized memory in zend_is_function_or_method_call().
27 lines
305 B
PHP
27 lines
305 B
PHP
--TEST--
|
|
Array offsets can be yielded by reference
|
|
--FILE--
|
|
<?php
|
|
|
|
function &gen(array &$array) {
|
|
yield $array[0];
|
|
}
|
|
|
|
$array = [1, 2, 3];
|
|
$gen = gen($array);
|
|
foreach ($gen as &$val) {
|
|
$val *= -1;
|
|
}
|
|
var_dump($array);
|
|
|
|
?>
|
|
--EXPECT--
|
|
array(3) {
|
|
[0]=>
|
|
&int(-1)
|
|
[1]=>
|
|
int(2)
|
|
[2]=>
|
|
int(3)
|
|
}
|