mirror of
https://github.com/php/php-src.git
synced 2025-08-20 01:14:28 +02:00
foreach only allowed variables to be traversed by reference. This never
really made sense because
a) Expressions like array(&$a, &$b) can be meaningfully iterated by-ref
b) Function calls can return by-ref (so they can also be meaningfully
iterated)
c) Iterators could at least in theory also be iterated by-ref (not
sure if any iterator makes use of this)
With by-ref generators the restriction makes even less sense, so I removed
it altogether.
18 lines
231 B
PHP
18 lines
231 B
PHP
--TEST--
|
|
Temporary array expressions can be iterated by reference
|
|
--FILE--
|
|
<?php
|
|
|
|
$a = 'a';
|
|
$b = 'b';
|
|
|
|
foreach ([&$a, &$b] as &$value) {
|
|
$value .= '-foo';
|
|
}
|
|
|
|
var_dump($a, $b);
|
|
|
|
?>
|
|
--EXPECT--
|
|
string(5) "a-foo"
|
|
string(5) "b-foo"
|