Re: Re: PATCH: anonymous functions in PHP

From: Date: Thu, 20 Dec 2007 09:43:35 +0000
Subject: Re: Re: PATCH: anonymous functions in PHP
References: 1 2 3 4 5 6 7 8 9  Groups: php.internals 
Request: Send a blank email to internals+get-34123@lists.php.net to get a copy of this message
On 20/12/2007, Alexey Zakhlestin <indeyets@gmail.com> wrote: > On 12/20/07, Stanislav Malyshev <stas@zend.com> 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!"

« previous php.internals (#34123) next »