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 [2009/05/02 05:48] – moving status to declined 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.2+  * Version: 1.0
   * Date: June 16, 2008 (added)   * Date: June 16, 2008 (added)
   * Date: May  01, 2009 (declined)   * Date: May  01, 2009 (declined)
-  * Author: Philip Olson <philip@roshambo.org+  * Date: June 07, 2010 (re-opened) 
-  * Status: Declined +  * Author: Philip Olson <philip@php.net>, Felipe Pena <felipe@php.net
 +  * Status: Implemented in PHP 5.4
 ===== Introduction ===== ===== Introduction =====
  
-Note: This RFC was given the "declined" status because it was never implemented or strongly desired. However, no official discussion exists to "decline" except CVS does not lie, and it's not in CVS. +This RFC proposes the implementation of array dereferencing of method/function return.
- +
-This RFC is incomplete and exists as a historical record for the discussion of this feature request.+
  
 ===== 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 21: 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 34: 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 49: 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.1241243315.txt.gz · Last modified: 2017/09/22 13:28 (external edit)