[php-src] Issue #10369: Foreach repeating last entry in array
| From: | waveney | Date: | Wed, 18 Jan 2023 15:13:17 +0000 |
| Subject: | [php-src] Issue #10369: Foreach repeating last entry in array | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-243487@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/10369
Author: waveney
### Description
The following code:
$Arr = [1,2,3,4,5,6];
foreach($Arr as &$a) echo "$a ";
echo "\n";
foreach($Arr as $a) echo "$a ";
echo "\n";
foreach($Arr as &$a) echo "$a ";
echo "\n";
```php
<?php
```
Resulted in this output:
```
1 2 3 4 5 6
1 2 3 4 5 5
1 2 3 4 5 5
```
But I expected this output instead:
1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4 5 6
The array itself is not corrupted, its the way it is iterated over by foreach is in error
```
```
### PHP Version
PHP 8.1.2
### Operating System
Ubuntu 22.04.1 LTS