早起的版本如 PHP5.6 ,绑定并调用闭包使用 bindTo,而PHP7 中 Closure :: call()方法具备更好的性能,废话很少说,php
<?php class Person { private $name = '乔峰'; } $getName = function() { return $this->name; }; // Bind a clousure $value = $getName->bindTo(new Person, 'Person'); print($value());// 乔峰
<?php class Person { private $name = '乔峰'; } $getName = function() { return $this->name; }; print($getName->call(new Person));//乔峰 注意 这里能够直接是 new person,固然new person()也能够