Re: [RFC] [VOTE] Short Closures

From: Date: Tue, 22 Sep 2015 19:24:34 +0000
Subject: Re: [RFC] [VOTE] Short Closures
References: 1 2 3 4 5 6 7  Groups: php.internals 
Request: Send a blank email to internals+get-88419@lists.php.net to get a copy of this message
On Tue, Sep 22, 2015 at 9:24 PM, Bob Weinand <bobwei9@hotmail.com> wrote: > > Am 22.09.2015 um 20:05 schrieb Dmitry Stogov <dmitry@zend.com>: > > The current PHP version emits two warning on similar constructs, and this > is explainable because we explicitly "use" $y. > > $ sapi/cli/php -r 'function foo(){(function($x) use ($y){$y=3; return > $y+$x;})(5);return $y;} var_dump(foo());' > PHP Notice: Undefined variable: y in Command line code on line 1 > > PHP Notice: Undefined variable: y in Command line code on line 1 > > NULL > > Thanks. Dmitry. > > > Well, yes. But that obviously needs alternate handling here as we don't > have full analysis to look at whether we'd need to import or not. Hence we > just are importing everything if it's used in Closure scope and defined in > parent scope. > > Because we obviously don't want this to emit a notice: > > function foo() { > return ($x ~> { > $y = 2; > return $x + $y; > })(10); > } > > Else it'd be totally impossible to define any variables... > > Also, the long form sets $y to NULL in the Closure (we just have two > notices there because you return $y; too… if you remove that, you'll be > left with just one notice. > I saw, you have fixed that warning on implicit use. Thanks. Dmitry. > > Bob >

« previous php.internals (#88419) next »