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

- Thread: https://externals.io/message/61404
- Original archive: https://news-web.php.net/php.internals/61404
- Started by Laruence on 2012-07-18T14:54:14+00:00
- Messages: 14
- RFC: Allow use T_AS in closure use statement (Withdrawn) — https://externals.io/rfc/useas.md
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #61404 — Laruence — 2012-07-18T14:54:14+00:00

URL: https://externals.io/message/61404#61404

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/

---

## #61406 — Leigh — 2012-07-18T15:19:51+00:00

URL: https://externals.io/message/61404#61406 · In reply to: #61404

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)


> 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/

---

## #61407 — Laruence — 2012-07-18T15:21:29+00:00

URL: https://externals.io/message/61404#61407 · In reply to: #61406

> 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
>
> 
> > […]
>



-- 
Laruence  Xinchen Hui
http://www.laruence.com/

---

## #61453 — Laruence — 2012-07-19T01:53:06+00:00

URL: https://externals.io/message/61404#61453 · In reply to: #61407

Hi:
    I saw you two vote against for this RFC.

    could you explain why?  then maybe I can improve it.

thanks


> 
> > […]
> sorry, no, it's only support literal variable for now.
>
> thanks
> > […]
>
>
>
> --
> Laruence  Xinchen Hui
> http://www.laruence.com/



-- 
Laruence  Xinchen Hui
http://www.laruence.com/

---

## #61455 — Kris Craig — 2012-07-19T02:38:09+00:00

URL: https://externals.io/message/61404#61455 · In reply to: #61453

> 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

---

## #61485 — Anthony Ferrara — 2012-07-19T14:13:15+00:00

URL: https://externals.io/message/61404#61485 · In reply to: #61453

Laruence,



> 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

---

## #61489 — Ivan Enderlin @ Hoa — 2012-07-19T14:39:42+00:00

URL: https://externals.io/message/61404#61489 · In reply to: #61406

> 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)
> 
>
> > […]

-- 
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/

---

## #61508 — Sara Golemon — 2012-07-19T18:17:37+00:00

URL: https://externals.io/message/61404#61508 · In reply to: #61404

Did the voting close already?  One day seems awfully short. :(



> 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/

---

## #61514 — Nikita Popov — 2012-07-19T19:59:52+00:00

URL: https://externals.io/message/61404#61514 · In reply to: #61508

> 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

---

## #61591 — Stas Malyshev — 2012-07-20T23:02:51+00:00

URL: https://externals.io/message/61404#61591 · In reply to: #61404

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

---

## #61597 — Ferenc Kovacs — 2012-07-21T00:50:16+00:00

URL: https://externals.io/message/61404#61597 · In reply to: #61591

On Sat, Jul 21, 2012 at 1:02 AM, Stas Malyshev <smalyshev@sugarcrm.com>wrote:

> Hi!
>
> > […]
>
> 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

---

## #61599 — Stas Malyshev — 2012-07-21T05:47:15+00:00

URL: https://externals.io/message/61404#61599 · In reply to: #61597

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

---

## #61605 — Pierre Joye — 2012-07-21T08:13:20+00:00

URL: https://externals.io/message/61404#61605 · In reply to: #61404

hi Laruence,


> 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

---

## #61607 — Laruence — 2012-07-21T08:31:36+00:00

URL: https://externals.io/message/61404#61607 · In reply to: #61605

> hi Laruence,
>
> 
> > […]
>
> 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/
