[PHP] Binding object instances to static closures

2013-05-31 Thread Nathaniel Higgins
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 =

Re: [PHP] Binding object instances to static closures

2013-05-31 Thread David Harkness
On Fri, May 31, 2013 at 10:54 AM, Nathaniel Higgins n...@nath.is wrote: Is it possible to bind an instance to a static closure, or to create a non-static closure inside of a static class method? PHP doesn't have a method to do this. In JavaScript you can use jQuery's var func =

Re: [PHP] Binding object instances to static closures

2013-05-31 Thread Nathaniel Higgins
I'm talking about PHP 5.4. `bindTo` is a Closure method in PHP 5.4, and allows you to set the `$this` variable inside of a Closure. However, apparently you can't use it on Closures created inside static methods. I knew that you could create another function which would return the Closure,

Re: [PHP] Binding object instances to static closures

2013-05-31 Thread Nick Whiting
This will not work. As stated in the PHP documentation Static closures cannot have any bound object A static Closure has no context of this just as with any other static object. A workaround is to pass in the Closure as a parameter to achieve a similar result. class TestClass { public

Re: [PHP] Binding object instances to static closures

2013-05-31 Thread David Harkness
Thanks Nathaniel for the clarification about 5.4. We are still on 5.3 (and that only recently), so 5.4 is a ways off in our production systems. However, I'll read up on this since it may be useful in offline tools. On Fri, May 31, 2013 at 11:52 AM, Nick Whiting nwhit...@xstudiosinc.comwrote: