rfc:useas
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
rfc:useas [2012/04/12 14:58] – created laruence | rfc:useas [2017/09/22 13:28] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 2: | Line 2: | ||
* Version: 1.0 | * Version: 1.0 | ||
* Date: 2012/04/12 | * Date: 2012/04/12 | ||
- | * Author: Xinchen Hui < | + | * Author: Xinchen Hui < |
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
Line 10: | Line 10: | ||
Allow use AS in the closure declaration, | Allow use AS in the closure declaration, | ||
- | < | + | < |
<?php | <?php | ||
$foo = " | $foo = " | ||
| | ||
- | $func = function () ues ($foo as $dup, &$foo as $ref) { //alias name | + | $func = function () use ($foo as $dup, &$foo as $ref) { //alias name |
}; | }; | ||
| | ||
Line 21: | Line 21: | ||
===== Proposal ===== | ===== Proposal ===== | ||
- | I have made a patch, | + | I have made a patch, |
- | < | + | |
+ | < | ||
<?php | <?php | ||
+ | |||
+ | $a = " | ||
+ | |||
+ | $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 | + | |
- | return function() use ($this as $obj) //Error | + | return function () use ($this as $obj) { |
- | | + | var_dump($obj); |
- | | + | |
+ | } | ||
} | } | ||
+ | |||
+ | $foo = new Foo(); | ||
+ | |||
+ | $a = $foo-> | ||
+ | $a(); | ||
</ | </ | ||
- | ==== Patch ==== | + | will output: |
+ | < | ||
+ | 2224object(Foo)# | ||
+ | } | ||
+ | </ | ||
- | * https:// | + | I will be keeping improve this patch. |
- | ===== Changelog | + | ===== Patch ===== |
- | * 2012-04-12 Xinchen Hui Initial version | + | |
+ | * https:// | ||
+ | |||
+ | ===== 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.1334242690.txt.gz · Last modified: 2017/09/22 13:28 (external edit)