[php-src] Issue #13046: "Attempting to set reference to non referenceable value" upon array destructuring by reference
| From: | bwoebi | Date: | Fri, 29 Dec 2023 03:47:12 +0000 |
| Subject: | [php-src] Issue #13046: "Attempting to set reference to non referenceable value" upon array destructuring by reference | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-246153@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/13046
Author: bwoebi
### Description
The following code:
```php
<?php
$someglobal = 1;
function foo() {
global $someglobal;
return [&$someglobal];
}
list(&$ref) = foo();
++$ref;
var_dump($someglobal);
```
Resulted in this output:
```
Notice: Attempting to set reference to non referenceable value in /tmp/preview on line 10
int(1)
```
But I expected this output instead:
```
int(2)
```
Making foo return by reference silences this warning, i.e. this is a valid workaround:
```
function &foo() {
global $someglobal;
$ref = [&$someglobal];
return $ref;
}
```
But in reality, the array itself should not need to return by reference, if we only desire to access
a by-reference value within the array.
### PHP Version
PHP 7.3-8.3
### Operating System
_No response_