Re: PATCH: anonymous functions in PHP

From: Date: Sat, 24 Mar 2007 23:22:20 +0000
Subject: Re: PATCH: anonymous functions in PHP
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-28590@lists.php.net to get a copy of this message
--- Jim Wilson <wilson.jim.r@gmail.com> wrote: > > Lexical anonymous functions would be enough for me. If these proposed > > lexical anonymous functions could automagically bind themselves > > to an instance's $this when called from within an object's scope (so as to > act > > as virtual methods), that would be grand. > > I agree - I don't need closures, but anonymous functions would be great. > > Perhaps a very minor point, but using create_function requires that the code > is an executable string. From a maintainability standpoint, this is a > little weird since it won't be syntax-highlighted etc. (Again, very very > minor). > > Question: If lexical anonymous functions were added, could this be used with > preg_replace and the 'e' modifier? > > So instead of: > preg_replace('/some_pattern/e', 'base64_encode($0)', $someVar); > > We could use: > preg_replace('/some_pattern/e', function ($matches) { > return base64_encode($matches[0]); > }, $someVar); > > I'd love this. Check out preg_replace_callback(), it should free you from the /e modifier. - Peter Send instant messages to your online friends http://au.messenger.yahoo.com

« previous php.internals (#28590) next »