rfc:functionarraydereferencing

Differences

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

Link to this comparison view

Next revision
Previous revision
rfc:functionarraydereferencing [2008/06/16 21:32] – initial commit philiprfc:functionarraydereferencing [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== Function Array Dereferencing (FAD) ====== ====== Function Array Dereferencing (FAD) ======
-  * Version: 0.+  * Version: 1.0 
-  * Date: June 16, 2008 +  * Date: June 16, 2008 (added) 
-  * Author: Philip Olson <philip@roshambo.org+  * Date: May  01, 2009 (declined) 
-  * Status: Information Gathering +  * Date: June 07, 2010 (re-opened) 
 +  * Author: Philip Olson <philip@php.net>, Felipe Pena <felipe@php.net
 +  * Status: Implemented in PHP 5.4
 ===== Introduction ===== ===== Introduction =====
  
-This RFC is incomplete and [currently] exists as a historical record for the discussion of this feature request.+This RFC proposes the implementation of array dereferencing of method/function return.
  
 ===== Proposal and Patch ===== ===== Proposal and Patch =====
  
-No proposal, or patch, as this is simply information gathering for archival purposes.+Patch: http://felipe.ath.cx/diff/array_dereference.diff
  
 ===== Examples ===== ===== Examples =====
Line 18: 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 31: Line 33:
 <code php> <code php>
 <?php <?php
 +
 +function fruit () {
 +  return array('a' => 'apple', 'b' => 'banana');
 +}
  
 $fruits = fruit(); $fruits = fruit();
 echo $fruits['a']; echo $fruits['a'];
  
-function fruit () { +?> 
-  return array('a' => 'apple', 'b' => 'banana');+</code> 
 + 
 +Working with references: 
 + 
 +<code php> 
 +<?php 
 +function &foo(&$foo) { 
 + return $foo;
 } }
 + 
 +$a = array(1);
 +$b = foo($a)[0];
 +$b = 2;
 +var_dump($b); // array(1) {  [0]=>  int(2) }
 +
 +?>
 +</code>
 +
 +Chaining:
 +
 +<code php>
 +<?php
 +
 +class foo {
 + public $array = array();
 +
 + public function __construct() {
 + $this->array = array(1, 2.3);
 + }
 +
 + public function bar() {
 + return $this->array;
 + }
 +}
 +
 +$foo = new foo;
 +var_dump($foo->bar()[1]); // float(2.3)
 +$foo->array[] = $foo;
 +var_dump($foo->bar()[2]->bar()[2]->array[0]); // int(1)
 +
 ?> ?>
 </code> </code>
Line 46: 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, 2010http://markmail.org/message/3ancnjwqhax47n2j 
-===== Where to go next ===== +  * June 7, 2010: http://markmail.org/message/unplu5x3gjjjydwz [Patch proposal]
- +
-Tasks+
-  * Find and list additional discussions about this topic +
-  * Research its implementation and impact +
-  * Write a proper RFC+
rfc/functionarraydereferencing.1213651936.txt.gz · Last modified: 2017/09/22 13:28 (external edit)