rfc:functionarraydereferencing

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
rfc:functionarraydereferencing [2010/06/07 20:22] – Credits for rfc feliperfc:functionarraydereferencing [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 5: Line 5:
   * Date: June 07, 2010 (re-opened)   * Date: June 07, 2010 (re-opened)
   * Author: Philip Olson <philip@php.net>, Felipe Pena <felipe@php.net>   * Author: Philip Olson <philip@php.net>, Felipe Pena <felipe@php.net>
-  * Status: Open +  * Status: Implemented in PHP 5.4
 ===== Introduction ===== ===== Introduction =====
  
Line 20: Line 19:
 <code php> <code php>
 <?php <?php
- 
-echo fruit()['a']; // apple 
  
 function fruit () { function fruit () {
   return array('a' => 'apple', 'b' => 'banana');   return array('a' => 'apple', 'b' => 'banana');
 } }
 +
 +echo fruit()['a']; // apple
 +
 ?> ?>
 </code> </code>
Line 33: Line 33:
 <code php> <code php>
 <?php <?php
- 
-$fruits = fruit(); 
-echo $fruits['a']; 
  
 function fruit () { function fruit () {
   return array('a' => 'apple', 'b' => 'banana');   return array('a' => 'apple', 'b' => 'banana');
 } }
 +
 +$fruits = fruit();
 +echo $fruits['a'];
 +
 ?> ?>
 </code> </code>
Line 47: Line 48:
 <code php> <code php>
 <?php <?php
- 
 function &foo(&$foo) { function &foo(&$foo) {
  return $foo;  return $foo;
 } }
 + 
 +$a = array(1);
 +$b = foo($a)[0];
 +$b = 2;
 +var_dump($b); // array(1) {  [0]=>  int(2) }
  
-$a = array(1); 
-foo($a)[0] = 2; 
-var_dump($a); // array(1) {  [0]=>  int(2) } 
 ?> ?>
 </code> </code>
Line 79: Line 81:
 $foo->array[] = $foo; $foo->array[] = $foo;
 var_dump($foo->bar()[2]->bar()[2]->array[0]); // int(1) var_dump($foo->bar()[2]->bar()[2]->array[0]); // int(1)
 +
 ?> ?>
 </code> </code>
Line 87: Line 90:
   * April 3, 2004: http://markmail.org/message/sbnrb7nekwy7xt3x   * April 3, 2004: http://markmail.org/message/sbnrb7nekwy7xt3x
   * November 9, 2006: http://markmail.org/message/5bv6mtd7zorni7gc   * November 9, 2006: http://markmail.org/message/5bv6mtd7zorni7gc
 +  * June 3, 2010: http://markmail.org/message/3ancnjwqhax47n2j 
 +  * June 7, 2010: http://markmail.org/message/unplu5x3gjjjydwz [Patch proposal]
rfc/functionarraydereferencing.1275942160.txt.gz · Last modified: 2017/09/22 13:28 (external edit)