Re: [PATCH] [RFC] Closures and lambda functions in PHP

From: Date: Fri, 20 Jun 2008 16:00:07 +0000
Subject: Re: [PATCH] [RFC] Closures and lambda functions in PHP
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-38479@lists.php.net to get a copy of this message
On Fri, 2008-06-20 at 10:50 -0500, Larry Garfield wrote: > On Fri, 20 Jun 2008 16:33:08 +0200, Alexander Wagner <waqner@gmx.net> wrote: > > On Friday 20 June 2008, Larry Garfield wrote: > >> > function ($x, $y) use ($a, $b, &$c) {}; > >> > >> I am not sure if "use" is the clearest word to use there (wouldn't > > lexical > >> there make more sense?) > > > > I agree. "use" for both namespaces and closures may not be a good idea. > > Otherwise +1 to this syntax for its low WTF-factor. > > Look like parameters. Behave like parameters. > > > > Also, allowing this for regular function definitions might be a nice > > long-term > > replacement for global. > > Totally silly idea: > > function foo($a, $b, &$c) global ($d, &$e) { > // ... > } > > $myfunc = lambda($a, $b, &$c) lexical ($d, &$e) { > // ... > } > > That puts all the information in the declaration line with parallel syntax and semantics, and > would even allow both by-val and by-ref usage for both lexical and global values. The following > would then be exactly equivalent functionality-wise: > > function foo() global (&$a) { > // ... > } > > function foo() { > global $a; > // ... > } > > Is that too crazy an idea? I like that, and also like the parenthesis on both parameter listings for greater readability. In a related question, would the following be a natural extension? $myfun = lambda($a, $b, &$c) lexical ($d, &$e) global ($f, &$g){ // ... } Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP

« previous php.internals (#38479) next »