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:34] – bp1222 | rfc:list_reference_assignment [2017/01/04 16:05] – bp1222 | ||
---|---|---|---|
Line 82: | Line 82: | ||
(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 125: | ||
===== 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 ===== | ===== Open Issues ===== | ||
- | ==== Multi Layer list() | + | ==== Both Syntax |
- | Not knowing if multiple layers of lists() below may include a reference, it's hard to determine | + | The proposal follows the syntactic choice in allowing you to specify to each element in the list() which should be referenced into the target array. |
- | <code php> | + | <file php> |
- | $a = [1, 2]; | + | <?php |
- | list($one, $two, list($three)) = $a; | + | $array = [1, 2, 3]; |
- | /* | + | list($a, $b, $c) =& $array; |
- | Notice: Undefined offset: 2 in / | + | </file> |
- | array(3) { | + | |
- | [0]=> | + | |
- | int(1) | + | |
- | [1]=> | + | |
- | int(2) | + | |
- | [2]=> | + | |
- | NULL | + | |
- | } | + | |
- | */ | + | |
- | list($one, $two, list(& | + | Which would be identical to proposed syntax: |
- | var_dump($a); | + | < |
- | /* | + | <?php |
- | Notice: Undefined offset: 2 in / | + | $array = [1, 2, 3]; |
- | Notice: Undefined offset: 0 in / | + | list(&$a, &$b, &$c) = $array; |
- | array(3) { | + | </file> |
- | [0]=> | + | |
- | int(1) | + | |
- | | + | |
- | int(2) | + | |
- | [2]=> | + | |
- | | + | |
- | [0]=> | + | |
- | &NULL | + | |
- | } | + | |
- | } | + | |
- | */ | + | |
===== Proposed Voting Choices ===== | ===== Proposed Voting Choices ===== |
rfc/list_reference_assignment.txt · Last modified: 2017/12/09 12:43 by nikic