Re: [RFC] Allow "use( $longname as $alias)" syntax for closures declaration

From: Date: Fri, 13 Apr 2012 10:36:02 +0000
Subject: Re: [RFC] Allow "use( $longname as $alias)" syntax for closures declaration
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-59872@lists.php.net to get a copy of this message
Hi, 2012/4/13 Laruence <laruence@php.net>: > On Fri, Apr 13, 2012 at 4:19 PM, Yasuo Ohgaki <yohgaki@ohgaki.net> wrote: >> Hi, >> >> 2012/4/13 Verbitsky Alexander <verbitsky_alexandr@mail.by>: >>> On 04/12/2012 06:38 PM, Laruence wrote: >>>> >>>> Hi: >>>>      I have made a RFC to allow user use T_AS in the closure declaration, >>>> like: >>>> >>>>      function () use($long as $l,&$long as $r) { >>>> >>>>      } >>>> >>>>      here is the RFC: >>>> https://wiki.php.net/rfc/useas >>>> >>>>      any ideas?  thanks >>>> >>> Closure is a functional literal that can pull with itself all variables >>> visible in current scope where it was created. For my opinion using keyword >>> 'use' is not necessary and i would have removed it. If you need different >>> name of variable maybe you need anonymous function. >>> >> >> You might be used to other language's scoping, but >> this is the way PHP works. > closure was not the way PHP works.  but now,  it has be introduced in PHP >> >> Named function cannot do this, but anyway >> function FUNC($a, $b, $c) uses ($d, $e, $f) {} >> is like >> function FUNC($a, $b, $c) { global $d, $e, $f; } > > they do are different,  previous is a lexical variable.  that means it > equal to the value when the closure is created. > > the latter is the value when it was called. Thanks for correction. I should have mentioned that. It's only similar that these are importing outside vars into current scope. Importing is the same, but scope is not. I wander if there are any good named function usage that imports current scope vars. Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net

« previous php.internals (#59872) next »