rfc:useas
Request for Comments: Allow use T_AS in closure use statement
- Version: 1.0
- Date: 2012/04/12
- Author: Xinchen Hui laruence@php.net
- Status: Withdrawn
- First Published at: http://wiki.php.net/rfc/useas
Introduction
Allow use AS in the closure declaration, like:
<?php $foo = "bar"; $func = function () use ($foo as $dup, &$foo as $ref) { //alias name };
Proposal
I have made a patch, after patch, the following script:
<?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 { public function closure() { return function () use ($this as $obj) { var_dump($obj); }; } } $foo = new Foo(); $a = $foo->closure(); $a();
will output:
2224object(Foo)#2 (0) { }
I will be keeping improve this patch.
Patch
Changelog
- 2012-04-12 Xinchen Hui Initial version
- 2012-07-18 Xinchen Hui Open voting
- 2012-07-19 Xinchen Hui Draw back, add dynamic variable supporting
rfc/useas.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1