php-src/Zend/tests/foreach_temp_array_expr_with_refs.phpt
Nikita Popov de80e3ce4b Remove reference restrictions from foreach
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.
2012-07-22 14:33:25 +02:00

19 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"