Call for voting: [RFC] Allow use T_AS in closure use statement

php.internals

Laruence

14 years ago
Hi: Call for voting for "Allow use T_AS in closure use statement", https://wiki.php.net/rfc/useas#voting any comment will be appreciated. thanks
-- Laruence Xinchen Hui http://www.laruence.com/

Leigh

14 years ago
I missed the discussion on this one, the RFC examples are very simple. Does it support aliasing array indices? For example: (use $matches[0] as $name) On Jul 18, 2012 3:55 PM, "Laruence" <laruence@php.net> wrote:

Laruence

14 years ago
On Wed, Jul 18, 2012 at 11:19 PM, Leigh <leight@gmail.com> wrote:
> I missed the discussion on this one, the RFC examples are very simple. Does > it support aliasing array indices? > > For example: (use $matches[0] as $name)
sorry, no, it's only support literal variable for now. thanks
> > On Jul 18, 2012 3:55 PM, "Laruence" <laruence@php.net> wrote: >> >> Hi: >> Call for voting for "Allow use T_AS in closure use statement", >> https://wiki.php.net/rfc/useas#voting >> >> any comment will be appreciated. >> >> thanks >> >> -- >> Laruence Xinchen Hui >> http://www.laruence.com/ >> >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php >> >
-- Laruence Xinchen Hui http://www.laruence.com/

Laruence

14 years ago
Hi: I saw you two vote against for this RFC. could you explain why? then maybe I can improve it. thanks On Wed, Jul 18, 2012 at 11:21 PM, Laruence <laruence@php.net> wrote:
> On Wed, Jul 18, 2012 at 11:19 PM, Leigh <leight@gmail.com> wrote: >> I missed the discussion on this one, the RFC examples are very simple. Does >> it support aliasing array indices? >> >> For example: (use $matches[0] as $name) > sorry, no, it's only support literal variable for now. > > thanks >> >> On Jul 18, 2012 3:55 PM, "Laruence" <laruence@php.net> wrote: >>> >>> Hi: >>> Call for voting for "Allow use T_AS in closure use statement", >>> https://wiki.php.net/rfc/useas#voting >>> >>> any comment will be appreciated. >>> >>> thanks >>> >>> -- >>> Laruence Xinchen Hui >>> http://www.laruence.com/ >>> >>> -- >>> PHP Internals - PHP Runtime Development Mailing List >>> To unsubscribe, visit: http://www.php.net/unsub.php >>> >> > > > > -- > Laruence Xinchen Hui > http://www.laruence.com/
-- Laruence Xinchen Hui http://www.laruence.com/

Kris Craig

14 years ago
On Wed, Jul 18, 2012 at 6:53 PM, Laruence <laruence@php.net> wrote:
> Hi: > I saw you two vote against for this RFC. > > could you explain why? then maybe I can improve it. > > thanks > >
I can't speak for them, but it might have something to do with a lack of information. I don't recall seeing the discussion thread on this, either. Though I could've just missed it. More specifics I think would be helpful. --Kris

Anthony Ferrara

14 years ago
Laruence, On Wed, Jul 18, 2012 at 9:53 PM, Laruence <laruence@php.net> wrote:
> Hi: > I saw you two vote against for this RFC. > > could you explain why? then maybe I can improve it. > > thanks
The reason that I voted against it is simple. It's sugar to make it harder to understand what the code is doing, and blur the line of what the closure is doing. Closures are supposed to "wrap" a parent scope (in other words, "close in on it"). The closure isn't a strictly new scope, but an extension on the existing one. PHP muddied this concept with the USE declaration (rather than importing the parent scope in its entirety, as almost every other language does). But this change would muddy it even further. My argument would be that if you really need to rename variables for clarity, you don't belong putting it in a closure in the first place (as it's way too much logic that needs to be split out into a separate function entirely). Additionally, it will further confuse the subject because: $f = function() use ($this as $obj) { $obj->protectedMethod(); // fatal error, as it's not in the same scope } That will fail for non-obvious reasons. At least currently there's an extra level of indirection required to pass $this, so it's a little bit clearer that you're not passing `$this` to the object, but a copy of it. Additionally, we need to think about the coupling between the closure's scope and the parent scope. There is -by design- very tight coupling between them. And not even from a language level. The closure is defined *inside* of another function, at a specific point in execution to use certain aspects of the parent scope. That means that it's highly coupled to the parent function. Actually, it's has cohesion in almost all forms: Logical, Temporal, Procedural, Communicational, Sequential and Functional. The only form of cohesion that it doesn't directly and automatically have is Coincidental... Therefore, their scopes are always going to be tightly coupled (which is what we want with a closure). If you really need to rename variables into the closure, create a factory for the closure: $closureFactory = function ($a, $b, $c) { return function() use ($a, $b, $c) { }; }; Yes, it's an extra level of indirection, but that indirection is explicit rather than implied.... So, I guess in summary, I would say that I voted against it because it further blurs the line between what a closure is and what PHP implements (which is already fairly blurry). That's my $0.02 at least... Anthony

Ivan Enderlin @ Hoa

14 years ago
On 18/07/12 17:19, Leigh wrote:
> I missed the discussion on this one, the RFC examples are very simple. Does > it support aliasing array indices?
I have missed the discussion two. I can't vote but I don't feel confortable with this new notation. Wouldn't be better to make the “=” operator available in use()? It has the same semantics, no? Best regards :-).
> > For example: (use $matches[0] as $name) > On Jul 18, 2012 3:55 PM, "Laruence" <laruence@php.net> wrote: > >> Hi: >> Call for voting for "Allow use T_AS in closure use statement", >> https://wiki.php.net/rfc/useas#voting >> >> any comment will be appreciated. >> >> thanks >> >> -- >> Laruence Xinchen Hui >> http://www.laruence.com/ >> >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php >> >>
-- Ivan Enderlin Developer of Hoa http://hoa.42/ or http://hoa-project.net/ PhD. student at DISC/Femto-ST (Vesontio) and INRIA (Cassis) http://disc.univ-fcomte.fr/ and http://www.inria.fr/ Member of HTML and WebApps Working Group of W3C http://w3.org/

Sara Golemon

14 years ago
Did the voting close already? One day seems awfully short. :( On Wed, Jul 18, 2012 at 7:54 AM, Laruence <laruence@php.net> wrote:

Nikita Popov

14 years ago
On Thu, Jul 19, 2012 at 8:17 PM, Sara Golemon <pollita@php.net> wrote:
> Did the voting close already? One day seems awfully short. :(
Laruence closed the vote because he wanted to add aliasing of arbitrary expressions instead of just variables. Nikita

Stas Malyshev

14 years ago
Hi!
> Call for voting for "Allow use T_AS in closure use statement", > https://wiki.php.net/rfc/useas#voting > > any comment will be appreciated.
I think it would be useful to add some explanation why this change is useful, with specific code examples that it improves. Right now it seems to be lacking good use cases so it's not clear why one would need this - i.e., just renaming the variable doesn't seem all that important...
-- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227

Ferenc Kovacs

14 years ago
On Sat, Jul 21, 2012 at 1:02 AM, Stas Malyshev <smalyshev@sugarcrm.com>wrote:
> Hi! > > > Call for voting for "Allow use T_AS in closure use statement", > > https://wiki.php.net/rfc/useas#voting > > > > any comment will be appreciated. > > I think it would be useful to add some explanation why this change is > useful, with specific code examples that it improves. Right now it seems > to be lacking good use cases so it's not clear why one would need this - > i.e., just renaming the variable doesn't seem all that important... > >
For starters, maybe we could use a few examples from the previous thread about this rfc: http://www.mail-archive.com/internals@lists.php.net/msg57855.html I really liked the one example from Jordi ( http://www.mail-archive.com/internals@lists.php.net/msg57904.html)
-- Ferenc Kovács @Tyr43l - http://tyrael.hu

Stas Malyshev

14 years ago
Hi!
> For starters, maybe we could use a few examples from the previous thread > about this > rfc: http://www.mail-archive.com/internals@lists.php.net/msg57855.html > I really liked the one example from Jordi > (http://www.mail-archive.com/internals@lists.php.net/msg57904.html)
This is exactly the thing that should be on the RFC :)
-- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227

Pierre Joye

14 years ago
hi Laruence, On Wed, Jul 18, 2012 at 4:54 PM, Laruence <laruence@php.net> wrote:
> Hi: > Call for voting for "Allow use T_AS in closure use statement", > https://wiki.php.net/rfc/useas#voting > > any comment will be appreciated.
Well, that's why the discussions period is required. Please close the vote, begin a discussion period (2 weeks minimum), then go ahaed again for a vote once there you are done with the discussions. Cheers,
-- Pierre @pierrejoye | http://blog.thepimp.net | http://www.libgd.org

Laruence

14 years ago
On Sat, Jul 21, 2012 at 4:13 PM, Pierre Joye <pierre.php@gmail.com> wrote:
> hi Laruence, > > On Wed, Jul 18, 2012 at 4:54 PM, Laruence <laruence@php.net> wrote: >> Hi: >> Call for voting for "Allow use T_AS in closure use statement", >> https://wiki.php.net/rfc/useas#voting >> >> any comment will be appreciated. > > Well, that's why the discussions period is required. > > Please close the vote, begin a discussion period (2 weeks minimum), > then go ahaed again for a vote once there you are done with the > discussions. >
Pierre: actually, I proposed this 3month ago, but yeah, I have closed this vote, will proposal it again after I implement the dynamic variable supporting :) thanks
> Cheers, > -- > Pierre > > @pierrejoye | http://blog.thepimp.net | http://www.libgd.org
-- Laruence Xinchen Hui http://www.laruence.com/