rfc:useas

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:useas [2012/04/12 14:59] laruencerfc:useas [2012/04/12 15:43] – typo bjori
Line 2: Line 2:
   * Version: 1.0   * Version: 1.0
   * Date: 2012/04/12   * Date: 2012/04/12
-  * Author: Xinchen Hui <laruence@php.net)+  * Author: Xinchen Hui <laruence@php.net>
   * Status: Under Discussion   * Status: Under Discussion
   * First Published at: http://wiki.php.net/rfc/useas   * First Published at: http://wiki.php.net/rfc/useas
Line 10: Line 10:
 Allow use AS in the closure declaration, like: Allow use AS in the closure declaration, like:
  
-''+<code>
 <?php <?php
   $foo = "bar";   $foo = "bar";
      
-  $func = function () ues ($foo as $dup, &$foo as $ref) { //alias name+  $func = function () use ($foo as $dup, &$foo as $ref) { //alias name
   };   };
      
-''+</code>
  
 ===== Proposal ===== ===== Proposal =====
  
-I have made a patch,  but for nowit doesn't support alias $this, like+I have made a patch, after patch the following script
-''+ 
 +<code>
 <?php <?php
 +
 +$a = "2";
 +
 +$b = function() use (&$a as $b, $a as $c, $a as $e) {
 +    echo $b;
 +    echo $c;
 +    echo $e;
 +    $b = 4;
 +};
 +
 +$b();
 +
 +echo $a;
  
 class Foo { class Foo {
-   public function bar() { +    public function closure() { 
-      return function() use ($this as $obj) //Error +        return function () use ($this as $obj) { 
-      {}; +            var_dump($obj); 
-   }+        }; 
 +    }
 } }
-'' 
  
-==== Patch ====+$foo = new Foo(); 
 + 
 +$a = $foo->closure(); 
 +$a(); 
 +</code> 
 + 
 + will output: 
 +<code> 
 +2224object(Foo)#2 (0) { 
 +
 +</code>  
 + 
 +I will be keeping improve this patch. 
 + 
 + 
 +===== Patch =====
  
    * https://gist.github.com/2367913    * https://gist.github.com/2367913
Line 39: Line 68:
 ===== Changelog ===== ===== Changelog =====
    * 2012-04-12 Xinchen Hui Initial version    * 2012-04-12 Xinchen Hui Initial version
- 
rfc/useas.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1