[php-src] Issue #10825: Using null coalesce operator seems to loose variables passed as reference
| From: | dsentker24 | Date: | Fri, 10 Mar 2023 14:43:19 +0000 |
| Subject: | [php-src] Issue #10825: Using null coalesce operator seems to loose variables passed as reference | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-243888@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/10825
Author: dsentker24
### Description
The following code:
```php
<?php
$arr = [
'deep' => [
'bar' => 'foo',
],
];
foreach($arr['deep'] ?? [] as &$value) {
$value = 'x';
}
var_dump('x' === $arr['deep']['bar']);
```
Resulted in this output:
```
bool(false)
```
But I expected this output instead:
```
bool(true)
```
If you use a reference to an array in a foreach, the reference is lost as soon as you use the null
coalesce operator to check for existence.
### PHP Version
PHP 7.x, PHP 8.x
### Operating System
_No response_