$funcList = array(
'foo' => function(){},
'bar' => function(){}
);
foreach($funcList as $funcName=>$closure){
// 循环将 funcList 里面的函数抽取到外面!
// function $funcName{ $closure(); }
}
1
holyghost 2017-01-20 15:27:34 +08:00
```
<?php class a { protected $x = "x"; public function xy() { $funcList = array( 'foo' => function() { echo "a"; }, 'bar' => function() { echo "b"; } ); foreach ($funcList as $funcName => $closure) { $closure(); } } } $a = new a(); $a->xy(); ``` 或者 ``` <?php class b {} $obj = new b(); $obj->yz = function () { return 'b'; }; echo($obj->yz->__invoke()); ``` 不过。。。。有啥意义么 |