Hello George,

Monday, August 22, 2005, 9:53:02 PM, you wrote:


> On Aug 22, 2005, at 2:08 PM, Stanislav Malyshev wrote:

MB>>>> * Anonymous functions. The real stuff, not just some odd string 
MB>>>> passed to create_function().
MB>>>
MB>>>There were some others already asking for this, maybe we should at least
MB>>>give it a thought if it is doable at all, anybody?

> Just out of curiosity, what's bad in create_function and how "real" ones 
> should be different?


> Two major differences as I see it:

> 1) syntactical:  the amount of escaping/funkyjunk you need to do to
> have anonymous functions look like regular functions in their declaration
> is huge (yes, you can use heredocs, but they have their (big if you run up
> against them) limitations as well).

> 2) no garbage collection on them (so in something like perl, when you
> anonymous sub goes out of scope, it's cleaned up).

> 3) runtime vs. compiletime definition

> For me 3 is good the way it is (the whole point of anon. functions (for
> me) is to allow me to easily vary their definition at runtime).

> 2 I can see being a pain, but I don't consider it critical.

> 1 keeps me from using create_function - the required code is to obtuse
> to use in most cases - I really would like to be able to do:

> $max = function ($a, $b) {
>   return $a < $b?$b:$a;
> }

> (for why heredocs suck here, consider the case where I want to use constants 
> in the definition).

4) Speed/Security. create_function() takes a string which is compiled at
run-time. An unnamed function syntax would allow compilation at original
compile time thus allowing compiler caching (speed) and prevents from
executing modified code which is bad anyways (security). Last but not
least for small functions the syntax support leeds to much more readable
code, while on the other hand some tools might have trouble with
create_function() strings.

Best regards,
 Marcus

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to