Re: T_AS in closures

From: Date: Wed, 05 Mar 2014 22:46:38 +0000
Subject: Re: T_AS in closures
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-72953@lists.php.net to get a copy of this message
Hi, On Thu, Mar 6, 2014 at 12:26 AM, Stas Malyshev <smalyshev@sugarcrm.com> wrote: > Hi! > >> I was clicking on bugs.php.net/random today and I came across #54888, >> which is a feature request for the following syntax: >> >> $foo = 'whatever'; >> $bar = function() use ($foo as $baz) { /* use $baz here */ }; > > What this allows to do that simple $baz = $foo and use $baz wouldn't do? > I think adding syntax that does not substantially expand what you can do > is not right. It just makes language larger and harder to learn and > understand. To answer your question: nothing, except that $baz will only exist in the scope of the anonymous function. But this is not about something that can't be achieved with existing features, it's about cleaner code and to some extent - consistency with T_AS in foreach(), traits, namespaces; and also how regular functions would have local-scope names for variables that are passed to them.

« previous php.internals (#72953) next »