rfc:list_reference_assignment
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:list_reference_assignment [2016/12/31 17:35] – bp1222 | rfc:list_reference_assignment [2017/02/06 17:25] – bp1222 | ||
---|---|---|---|
Line 6: | Line 6: | ||
* Original Date: 2013-10-24 | * Original Date: 2013-10-24 | ||
* Original Author: Andrea Faulds, ajf@ajf.me | * Original Author: Andrea Faulds, ajf@ajf.me | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
Line 26: | Line 26: | ||
$a = $array[0]; | $a = $array[0]; | ||
$b =& $array[1]; | $b =& $array[1]; | ||
+ | </ | ||
+ | |||
+ | <code php> | ||
+ | /* Note; []= syntax works the same, so the following is functionally equivalent to the example */ | ||
+ | [$a, &$b] = $array; | ||
</ | </ | ||
Line 82: | Line 87: | ||
(notice here that the reference exists on '' | (notice here that the reference exists on '' | ||
- | The advantage of adding support for this is that it allows you to use reference assignment for multiple variables at once, which is not currently possible. The syntax here is different from the traditional assignment syntax which places the & before the rvar, not the lvar, but the advantage here is that you can reference assign some, but not all of the variables in list(). | ||
- | The RFC also takes into account the possibility of objects being the lval of the assignment implementing ArrayAccess. | + | The predominant advantage of adding support for this is that it allows you to use reference assignment for multiple variables at once, which is not currently possible. The syntax here is different from the traditional assignment syntax which places the ''&'' |
+ | |||
+ | The RFC also takes into account the possibility of objects being the r-val of the assignment implementing ArrayAccess. | ||
<code php> | <code php> | ||
class RefArr implements ArrayAccess { | class RefArr implements ArrayAccess { | ||
Line 124: | Line 130: | ||
===== RFC Impact ===== | ===== RFC Impact ===== | ||
==== To Opcache ==== | ==== To Opcache ==== | ||
- | I'm assuming yes, I'm not familiar with opcache. Changes were made to vm_def, and a new extended value is used. | + | Maybe, I don't know enough about opcache to say if changing current ops by adding an extended value would impact. |
- | ===== Open Issues | + | ===== Proposed Voting Choices |
- | ==== Multi Layer list() ==== | + | Voting starts on 2017-02-06 17:30 UTC and closes on 2017-02-22 20:00 UTC |
- | Not knowing if multiple layers of lists() below may include a reference, it's hard to determine if one of them is going to assign by reference | + | |
- | <code php> | + | 2/3 Vote Required |
- | $a = [1, 2]; | + | Vote Yes to allow reference assignments as part of list() assignments |
- | list($one, $two, list($three)) = $a; | + | Vote No to maintain current functionality |
- | /* | + | |
- | Notice: Undefined offset: 2 in / | + | |
- | array(3) { | + | |
- | | + | |
- | int(1) | + | |
- | [1]=> | + | |
- | int(2) | + | |
- | [2]=> | + | |
- | NULL | + | |
- | } | + | |
- | */ | + | |
- | list($one, $two, list(& | + | <doodle title=" |
- | var_dump($a); | + | * Yes |
- | /* | + | |
- | Notice: Undefined offset: 2 in / | + | </doodle> |
- | Notice: Undefined offset: 0 in / | + | |
- | array(3) { | + | |
- | [0]=> | + | |
- | int(1) | + | |
- | [1]=> | + | |
- | | + | |
- | [2]=> | + | |
- | array(1) { | + | |
- | [0]=> | + | |
- | &NULL | + | |
- | } | + | |
- | } | + | |
- | */ | + | |
- | </code> | + | |
- | + | ||
- | ===== Proposed Voting Choices ===== | + | |
- | Will require 2/3 | + | |
===== Patches and Tests ===== | ===== Patches and Tests ===== |
rfc/list_reference_assignment.txt · Last modified: 2017/12/09 12:43 by nikic