[php-src] Issue #15458: foreach with updated $record does not update $record
| From: | remco-pc | Date: | Sat, 17 Aug 2024 10:13:40 +0000 |
| Subject: | [php-src] Issue #15458: foreach with updated $record does not update $record | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-247520@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/15458
Author: remco-pc
### Description
The following code:
```php
<?php
$data = [];
foreach($tags as $row_nr => $list){
foreach($list as $nr => $record){
$variable_assign = Build::variable_assign($object, $flags, $options, $record);
if($variable_assign){
$data[] = $variable_assign . ';';
$next = $list[$nr + 1] ?? false;
if($next !== false){
$tags[$row_nr][$nr + 1] = Build::variable_assign_next($object, $flags,
$options, $next);
$list[$nr + 1] = $tags[$row_nr][$nr + 1];
d($list);
}
}
d($record);
}
}
ddd($data);
```
Resulted in this output:
```
d($list) -> debug $list
[
...,
[
'text' => '',
....
]
(list is updated with the new text value (removed an "\n" )
d($record) -> debug $record
[
'text' => "
"
]
(record is not updated with the new text value
```
But I expected this output instead:
```
Because i am in a foreach and update the next record with a new value, i expect the $record is
updated accordingly
```
### PHP Version
php 8.3
### Operating System
Debian 12