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

[email protected] (aliber4079)
Newsgroups php.bugs
Message-ID <22XWTmtxAfOBWIMozQYmzknfSK5KWFDBWrSqoZeLOYg@main.internal.php.net>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.