Binding object instances to static closures
[email protected] (Nathaniel Higgins)
| Newsgroups | php.general |
|---|---|
| Message-ID | <CAGH7SFbHMWTi6sFsZwt1TiaafOSJcOKGza0VQEdtEzVPUwHBBg@mail.gmail.com> |
Is it possible to bind an instance to a static closure, or to create a
non-static closure inside of a static class method?
This is what I mean...
<?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();