Binding object instances to static closures

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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();

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux