rfc:list_reference_assignment

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
rfc:list_reference_assignment [2016/12/31 17:35] bp1222rfc:list_reference_assignment [2017/01/11 22:38] bp1222
Line 26: Line 26:
 $a = $array[0]; $a = $array[0];
 $b =& $array[1]; $b =& $array[1];
 +</code>
 +
 +<code php>
 +/* Note; []= syntax works the same, so the following is functionally equivalent to the example */
 +[$a, &$b] = $array;
 </code> </code>
  
Line 82: Line 87:
 (notice here that the reference exists on ''$array[1][0]'' since $a is still in scope after the foreach()) (notice here that the reference exists on ''$array[1][0]'' since $a is still in scope after the foreach())
  
-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 ''&'' before the right-side value, not the left-side value; the advantage here is that you can reference assign some, but not all of the variables in list(). [See Open Issues] 
 + 
 +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 ===== ===== Open Issues =====
-==== Multi Layer list() ==== +==== Both Syntax ==== 
-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+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.  The question if if you wanted to reference everything, should we also support the syntax: 
 +<file php> 
 +<?php 
 +$array = [1, 2, 3]; 
 +list($a, $b, $c) =& $array; 
 +</file>
  
-<code php> +Which would be identical to proposed syntax: 
-$= [1, 2]; +<file php> 
-list($one, $two, list($three)) = $a+<?php 
-/* +$array = [1, 2, 3]; 
-Notice: Undefined offset: 2 in /Users/dwalker/src/php/e.php on line 3 +list(&$a, &$b, &$c) = $array
-array(3) { +</file>
-  [0]=> +
-  int(1) +
-  [1]=> +
-  int(2) +
-  [2]=> +
-  NULL +
-+
-*/ +
- +
-list($one, $twolist(&$three)) = $a; +
-var_dump($a); +
-/* +
-Notice: Undefined offset: 2 in /Users/dwalker/src/php/e.php on line 3 +
-Notice: Undefined offset: 0 in /Users/dwalker/src/php/e.php on line 3 +
-array(3) { +
-  [0]=> +
-  int(1) +
-  [1]=> +
-  int(2) +
-  [2]=> +
-  array(1) { +
-    [0]=> +
-    &NULL +
-  } +
-+
-*/ +
-</code>+
  
 ===== Proposed Voting Choices ===== ===== Proposed Voting Choices =====
rfc/list_reference_assignment.txt · Last modified: 2017/12/09 12:43 by nikic