PHP 7
Closure::call()
闭包函数动态
对象实例
描述:
public mixed Closure::call ( object $newthis [, mixed $... ] )
暂时将闭包绑定到newthis
,并用任何给定的参数调用。
php7之前的示例:
<?php class A { private $x = 1; } // PHP 7 之前版本定义闭包函数代码 $getXCB = function() { return $this->x; }; // 闭包函数绑定到类 A 上 $getX = $getXCB->bindTo(new A, 'A'); echo $getX(); print(PHP_EOL);
php7之后的示例:
<?php class A { private $x = 1; } $getX = function() { return $this->x; }; echo $getX->call(new A); ?>
以上就是PHP7中Closure :: call的使用范例的详细内容,更多请关注其它相关文章!
© 著作权归作者所有
举报
发表评论
0/200