|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80066 List Reference Assignment: Cannot reference an array value by return
Submitted: 2020-09-06 19:40 UTC Modified: 2020-09-06 20:53 UTC
Avg. Score:2.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: php-0919 at jan-runte dot de Assigned:
Status: Verified Package: Variables related
PHP Version: 7.3.22 OS: macOS 10.15.6
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: php-0919 at jan-runte dot de
New email:
PHP Version: OS:


 [2020-09-06 19:40 UTC] php-0919 at jan-runte dot de
Feature 7.3 - List Reference Assignment:

When attempting to transfer an array return value via the list reference assignment to certain keys with by-reference, the error "Attempting to set reference to non referenceable value" occurs.

But the belonging value of that key is a referenceable value - it is an array.

7.3.13: failed
7.3.22: failed
7.4.3: failed
7.4.10: failed
8.0.0beta2: failed
8.0.0beta3: failed

Test script:
function returnsArrayWithReferencedValue(array &$subject) : array {
    return [
        'a' => &$subject,
	'b' => 123,

$source = [
    'c' => [],


['a' => &$referencedArray] = returnsArrayWithReferencedValue($source);

// Throws an error: "Attempting to set reference to non referenceable value in ..."


// First set returned array to a variable
$returnedArray = returnsArrayWithReferencedValue($source);

$source['d'] = 456; // manipulate source array


// Fake returned array as a prepared variable
$fakeReturnedArray = [
    'a' => &$source,
    'b' => 123,	

['a' => &$referencedArray] = $fakeReturnedArray;
$source['d'] = 456; // manipulate source array

Expected result:
array(2) {
  array(0) {

Actual result:
Throws an error: Attempting to set reference to non referenceable value


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-09-06 20:53 UTC]
-Status: Open +Status: Verified
 [2020-09-06 20:53 UTC]
PHP is complaining because the function doesn't return by-reference. If it does then there's no error and everything works.

I don't think that requirement is necessary: the whole return value is not what is being referenced, only the items inside, and array items can certainly be references without their parent arrays being references too.
 [2022-12-27 08:06 UTC] janettabloomquist at gmail dot com
The solution is an array! An array can hold many values under a single name, and you can access the values by referring to an index number. Creating an Array. Arrays cannot be passed by value, therefore they cannot be returned. 
 [2024-05-09 05:20 UTC] patrick521fritz at gmail dot com
This php bug results is very great for me this is very nice. (
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jun 25 17:01:31 2024 UTC