# [RFC] list() Reference Assignment

- Thread: https://externals.io/message/69858
- Original archive: https://news-web.php.net/php.internals/69858
- Started by Andrea Faulds on 2013-10-24T22:14:21+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #69858 — Andrea Faulds — 2013-10-24T22:14:21+00:00

URL: https://externals.io/message/69858#69858

Good evening again,

Previously I wrote to this mailing list about my proposal to add 
reference assignment to list() with a new syntax ("[PHP-DEV] Proposal: 
Implement FR #7930 (list() constructor reference assignment)"). I have 
now opened an RFC:

https://wiki.php.net/rfc/list_reference_assignment

In brief, this allows you to write this:

$array = [1, 2];
$a = $array[0];
$b = &$array[1];

Like this instead:

$array = [1, 2];
list($a, &$b) = $array;

Reference assignments with list() work just like normal assignments, and 
you can still skip variables, use nested list()s, and use list() in 
foreach as usual.

There is a patch with a passing test, however a memory leak bug was 
found (thanks Nikita!), and so the patch can't be considered complete or 
final yet. I'm something of a novice at debugging PHP code at the 
moment, so any help fixing that would be appreciated, but I will try to 
fix it when I have more time.

The patch is here: https://bugs.php.net/bug.php?id=6768

The RFC has been added to the list in Under Discussion.

Any thoughts, suggestions, etc. appreciated.

Regards,
-- 
Andrea Faulds
http://ajf.me/

---

## #74236 — Andrea Faulds — 2014-05-15T19:12:41+00:00

URL: https://externals.io/message/69858#74236 · In reply to: #69858

Good evening,

So, I came back to this today. It appears to me that it’s actually impossible for me to implement this feature properly at the present moment, due to the parser directly emitting opcodes. This is a shame. Unfortunately, there’s really nothing I can do about it.

Hence, I hereby withdraw my RFC.

Thanks.



> Good evening again,
> 
> Previously I wrote to this mailing list about my proposal to add reference assignment to list() with a new syntax ("[PHP-DEV] Proposal: Implement FR #7930 (list() constructor reference assignment)"). I have now opened an RFC:
> 
> https://wiki.php.net/rfc/list_reference_assignment
> 
> In brief, this allows you to write this:
> 
> $array = [1, 2];
> $a = $array[0];
> $b = &$array[1];
> 
> Like this instead:
> 
> $array = [1, 2];
> list($a, &$b) = $array;
> 
> Reference assignments with list() work just like normal assignments, and you can still skip variables, use nested list()s, and use list() in foreach as usual.
> 
> There is a patch with a passing test, however a memory leak bug was found (thanks Nikita!), and so the patch can't be considered complete or final yet. I'm something of a novice at debugging PHP code at the moment, so any help fixing that would be appreciated, but I will try to fix it when I have more time.
> 
> The patch is here: https://bugs.php.net/bug.php?id=6768
> 
> The RFC has been added to the list in Under Discussion.
> 
> Any thoughts, suggestions, etc. appreciated.
> 
> Regards,
> -- 
> Andrea Faulds
> http://ajf.me/
> 
> -- 
> 
> 
> 

--
Andrea Faulds
http://ajf.me/
