[RFC] list() Reference Assignment
| From: | Andrea Faulds | Date: | Thu, 24 Oct 2013 22:14:21 +0000 |
| Subject: | [RFC] list() Reference Assignment | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-69858@lists.php.net to get a copy of this message | ||
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/