PHP closure
来源:互联网 发布:淘宝收藏的店铺在哪里 编辑:程序博客网 时间:2024/06/09 23:49
(PHP 5 >= 5.3.0, PHP 7) Class used to represent anonymous functions.
function createGreeter($who) {
return function() use ($who) {
echo "Hello $who";
};
}
$greeter = createGreeter("World");
$greeter(); // Hello World
===============================
<?phpclass A { public $base = 100;}class B { private $base = 1000;}$f = function () { return $this->base + 3;};$a = Closure::bind($f, new A);print_r($a());echo PHP_EOL;$b = Closure::bind($f, new B , 'B');print_r($b());echo PHP_EOL;
上面的例子中,f这个匿名函数中莫名奇妙的有个f这个匿名函数中莫名奇妙的有个this,这个this关键词就是说明这个匿名函数是需要绑定在类中的。
0 0
- PHP closure
- PHP closure 匿名函数
- PHP Closure类详解
- PHP 中的Closure
- PHP 中的Closure
- PHP Closure类详解
- PHP Closure类详解
- Google Closure Compiler with PHP
- PHP闭包(Closure)
- PHP Closure创建匿名函数
- PHP中的Closure闭包
- Closure
- closure
- closure
- Closure
- closure
- Closure
- Closure
- 看电影去
- JAVA设计模式--模板方法模式
- HDU 3498 舞蹈链精确覆盖
- [UWP]依赖属性1:概述
- Problem E. Bet(2016 China-Final)【高精度除法】
- PHP closure
- Web HTTP协议中URI和URL区别
- shell-01
- Python的验证码识别,模拟ajax请求,爬取优酷会员(滑稽)
- Dstream生成RDD实例详解
- HDU 3529 舞蹈链之可重复覆盖
- 《InsideUE4》UObject(四)类型系统代码生成
- java网络编程
- 线程间通信常用的三种方法