On 20/12/2007, Alexey Zakhlestin <[EMAIL PROTECTED]> wrote:
> On 12/20/07, Stanislav Malyshev <[EMAIL PROTECTED]> wrote:
> > > I think we need it. In the current incarnation, anonymous functions
> > > are so impractical to use, that it's a barrier. I think that is
> > > unfortunate, because it could be an interesting and useful direction
> > > to take for PHP. The users, who don't know what a closure is, could
> >
> > Direction like what?
>
> being able to do the following (and not to worry about runtime
> compilation) is a good reason on it's own:
>
> array_filter($my_data, function($test){ return 3 === ($test % 4) });

That makes perfect sense to me as I see/use this sort of code in JavaScript.

The argument about making the filter a global function is not sensible
to apply in all circumstances. In many cases the filter is only going
to be of use in an array_filter() call, so now we would have 2
functions to do the work of 1.

If you think about for() and foreach(), these are functional-ish
ideas. Iterators in general should quite happily support this idea.

Maybe a syntax like this would be more appealing ...

array_filter($my_data as $test) {
  return 4 === ($test % 4);
}

This sort of looks like a foreach, which is extremely readable.

Richard.

-- 
-----
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"

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

Reply via email to