【发布时间】:2013-05-27 14:48:41
【问题描述】:
是否可以将实例绑定到静态闭包,或者在静态类方法中创建非静态闭包?
这就是我的意思...
<?php
class TestClass {
public static function testMethod() {
$testInstance = new TestClass();
$testClosure = function() use ($testInstance) {
return $this === $testInstance;
};
$bindedTestClosure = $testClosure->bindTo($testInstance);
call_user_func($bindedTestClosure);
// should be true
}
}
TestClass::testMethod();
【问题讨论】:
标签: php binding static closures instance