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();
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.