[php-src] Issue #21040: Issue with foreach when used with reference "&" and reusing the same variable
[email protected] (djidel)
| Newsgroups | php.bugs |
|---|---|
| Message-ID | <[email protected]> |
Issue: https://github.com/php/php-src/issues/21040 Author: djidel ### Description The following code: ```php <?php $a = [1,2,3]; foreach($a as &$i) $i++; var_export($a); foreach($a as $i) $b = $i+1; var_export($a); ``` Resulted in this output: ``` array ( 0 => 2, 1 => 3, 2 => 4, )array ( 0 => 2, 1 => 3, 2 => 3, ) ``` But I expected this output instead: ``` array ( 0 => 2, 1 => 3, 2 => 4, )array ( 0 => 2, 1 => 3, 2 => 4, ) ``` ### PHP Version ```plain Tested on 8.3.21, 8.4.10, 8.2.29, 8.1.33, 8.2.20: ``` ### Operating System _No response_