On Dec 17, 2007 6:09 PM, Andi Gutmans <[EMAIL PROTECTED]> wrote:
> Don't have time right now but we should go back and re-read those
> discussions before opening a new one. I can probably do it over the next
> couple of days. I am not necessary against supporting such a solution
> but we need to make sure it's fully baked and that we clear know and
> agree on what is and what isn't supported (and that should be documented
> and not revisited every time someone comes and complains). Variable
> binding is one thing which would likely not make it into such an
> implementation unless there's a big shift in the intent of the patch.

Allow me to recap then.

Static lambdas (in lack of a better name) and create_function() differ
from each other in that the former happens at compile time, while the
latter happens at run time. The consequence of this is, that you can
bind (primitive) variables to the created function, with
create_function(), but not with static lambdas.
Functionally, create_function() is a variation of eval, which allows
you to create new code at runtime. Static lambda is syntactic sugar
for creating a function in the global scope, without knowing its name
at compile time. Static lambda is more restrictive than
create_function(), because there is no way to share scope between the
inner and the bounding function. This is specific for PHP, because the
language doesn't have static scope. Without going much into details, I
think it's pretty safe to say, that introducing static scope into PHP
is not only undesireable, but also technically impossible. So let's
not spend any time discussing that.

In brief, there are the following benefits of introducing static lambdas:
A1 Better readability.
A2 Syntactic errors happen at compile time, rather than run time.
A3 Better support for debugging/introspection.
A4 Optimisations are possible.

And the following problems:
B1 Users might assume, that lambdas have static scope.
B2 There is some overlap between the application of create_function()
and static lambdas, meaning some level of redundancy.
B3 Static lambdas are less powerful, since there is no way to bind variables.

If I missed any points, please bring them up. Otherwise, this is what
a decision should be based on. (And sorry for pointing out the
obvious, but _not_ making a decision, is a decision too)

Of the cons, B1 is probably the biggest issue. There are (at least)
two considerations to take here; First, how probable is it, that users
will make this assumption? And second, how much confusion will it
cause to those, which it affects?
The first question could perhaps be answered by a survey (Or less
scientifically, by random consensus), but the latter is rather
subjective. I'd like to make the argument, that those who will tend to
suffer most from peculiarities of scoping rules, are the same people,
who are less likely to have encountered static scope in the first
place. The simple rule, that PHP has dynamic scope, should be simple
to understand for anyone who actually knows the difference.

Did I miss anything?

-- 
troels

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

Reply via email to