[php-src] Issue #21283: iterating over the same array twice, first by reference and then by value seems to give different results

From: Date: Tue, 24 Feb 2026 03:14:51 +0000
Subject: [php-src] Issue #21283: iterating over the same array twice, first by reference and then by value seems to give different results
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-251716@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/21283 Author: aliber4079 ### Description The following code: ```php <?php $criteria=[ "a", "b", ]; var_dump($criteria); foreach ($criteria as &$criterion) { } foreach ($criteria as /*&*/$criterion){ } var_dump($criteria); ``` Resulted in this output: ``` array(2) { [0]=> string(1) "a" [1]=> string(1) "b" } array(2) { [0]=> string(1) "a" [1]=> &string(1) "a" } ``` But I expected this output instead: ``` array(2) { [0]=> string(1) "a" [1]=> string(1) "b" } array(2) { [0]=> string(1) "a" [1]=> &string(1) "b" } ``` ### PHP Version ```plain PHP 8.5.3 (cli) (built: Feb 10 2026 18:44:09) (ZTS Visual C++ 2022 x64) Copyright (c) The PHP Group Built by The PHP Group Zend Engine v4.5.3, Copyright (c) Zend Technologies with Zend OPcache v8.5.3, Copyright (c), by Zend Technologies ``` ### Operating System windows x64

« previous php.bugs (#251716) next »