[PHPTAL] Support for PHP 5.3 closures

Kornel Lesinski kornel at aardvarkmedia.co.uk
Wed Dec 23 20:17:05 CET 2009


On 23 Dec 2009, at 18:27, Iván Montes wrote:

> I fail to see why checking for closures makes variable access much  
> slower. As far as I remember, interpolated variable paths are  
> "compiled" to use the $ctx->path() method, and it already does quite  
> a few type checking logic already.
>
> Checking for a closure basically would mean adding "instanceof"  
> conditions, being instanceof an operator and as such extremely fast,  
> I don't see why it should hurt overall performance.

First path of component is optimized to be $ctx->var which reads value  
directly from a property of $ctx object. For simple cases like $ 
{variable} no function is called at all (not even __get()).

Without any extra syntax, it's not known at compilation time whether  
variable will be real value or a closure, so I won't be able optimize  
those checks away.

-- 
regards, Kornel




More information about the PHPTAL mailing list