On 3/22/07, Christian Schneider <[EMAIL PROTECTED]> wrote:
Michael Walter wrote:
> Which seems to fit Andi's $_SCOPE proposal.

Yes, but is a point against a real closure proposal.

I think the defining property of a "real" closure proposal is having
the lexical scope available.
So I guess we both agree on that something like $_SCOPE would be a
useful thing to have.

>> He said real-life examples (-:C
>
> Is that like "enterprise" examples? ;)

No, it's like non-textbook example (which can also run on a Bird of Prey
or a Klingon starship :-))

Closures become really useful when you start building abstractions on
top of anonymous functions, since in the process of abstraction you
often replace literals/constants by parameters (similar to how
function parameters become useful when you start refactoring common
code into functions ;).

A simple real-life example is:

function pick($member)
{
 return create_function('$x', 'return $x->'.$member.';');
}

which could be used e.g. in

 array_map(pick('age'), $people).

Arguably, in this case you could as well write:

 array_map(function($p) {return $p->age;}, $people);

but I believe it is easy to see how the problem generalizes.

Regards,
Michael

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

Reply via email to