[php-src] Issue #12928: array foreach with reference then without reference cause the incorrect last item
| From: | sunnydavis | Date: | Mon, 11 Dec 2023 09:16:50 +0000 |
| Subject: | [php-src] Issue #12928: array foreach with reference then without reference cause the incorrect last item | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-246029@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/12928
Author: sunnydavis
### Description
The following code:
```php
<?php
$ary = [
1,2,3,4,5,
];
foreach ($ary as &$a) {
}
foreach ($ary as $a) {
}
echo json_encode($ary);
```
Resulted in this output:
```
[1,2,3,4,4]
```
But I expected this output instead:
```
[1,2,3,4,5]
```
### PHP Version
PHP 7.2.34
### Operating System
Ubuntu 20.04