Closure::call()方法是一种快捷方式,用于将对象范围临时绑定到闭包并调用它。与PHP 5.6的 bindTo 相比,它的性能要快得多。
<?php class A { private $x=1; } //Define a closure Pre PHP 7 code $getValue=function() { return $this->x; }; //Bind a clousure $value=$getValue->bindTo(new A, 'A'); print($value()); ?>
输出-
链接:https://www.learnfk.comhttps://www.learnfk.com/php7+/php7-closure-call.html
来源:LearnFk无涯教程网
1
<?php class A { private $x=1; } //PHP 7+ code, Define $value=function() { return $this->x; }; print($value->call(new A)); ?>
输出-
链接:https://www.learnfk.comhttps://www.learnfk.com/php7+/php7-closure-call.html
来源:LearnFk无涯教程网
1
这一章《PHP - 闭包方法》你学到了什么?在下面做个笔记吧!做站不易,你的分享是对我们最大的支持,感谢!😊
Spring Cloud 微服务项目实战 -〔姚秋辰(姚半仙) - 〕
如何在 PHP 中通过 AJAX 发送的 formData 中循环序列化数据追加...
来自带有 CONCAT 的 REGEXP 的“重复运算符操作数无效”