"Investigate use of closures in PHPLinq"

Mar 30, 2011 at 11:16 AM

Hi,

I noticed your comment over at http://phplinq.codeplex.com/workitem/3870?ProjectName=phplinq

This has been something I always wanted to do, but... PHPLinq uses the string-based closures also for translating PHP code to SQL that is executed on your database. Is this possbile with native closures?

Best regards,
Maarten

Coordinator
Mar 30, 2011 at 11:43 AM

Hi Maarten,
to rewrite a closure function as SQL we need to know, inspect, tokenize and evaluate the methods body but this is not possible in runtime. I inspected reflection things in php badly but as I guessed there is no way to get functions body in runtime.

But there is another way. We can read source code in runtime also some debugging materials can provide some basic information about where the functions body is located lexically (I mean it can say line 19, column 34 etc. ) So we have a way to reach to functions body and yes it is a very dirty hack also slow. But the speed problem can be achieved with some sort of caching or some other clever techniques.

So, the answer is yes we can, we have a way but the way is very long to go :) Additionally we can open up a feature request to php guys and request the ability for getting "op-codes" of given closure.

Do you have any idea on this?

Mar 30, 2011 at 12:28 PM

Nope... Have been struggling with that back when I started PHPLinq and have chosen the string-based approach just for this reason. I'm not sure if there's an option to get the stack trace of the current line being evaluated, that would be interesting as you can then open the sources and try to figure out the closure's code.