Skip to content

Conversation

haskellcamargo
Copy link

@haskellcamargo haskellcamargo commented May 30, 2016

This pull-requests adds the support for dynamic variable names using strings on the scope of functions without the necessity of using global.

This would fail with a syntactic error before:

${'+'} = function ($x, $y) { return $x + $y; };

$test_add = (function ($a, $b) use (${'+'}) {
  return ${'+'}($a, $b);
})(10, 20);

echo $test_add;

The name ${'+'} wouldn't be be accessible without declaring it using the global keyword or using an alias.

The support for dynamic items has been added only for literal strings T_CONSTANT_ENCAPSED_STRING because we would have to evaluate the expression and then import the name without having a direct reference to the variable for variable variables, such as use ($$test). Well, I'll try to open a RFC to solve this a posteriori. I'm also planning to open a RFC to support aliases in function use, such as function () use (${'+'} as $plus) {} in order to preserve scope.

I have also implemented support for references to these variables:

${'+'} = 10;
(function () use (&${'+'}) {
  ${'+'} = 20;
})();
echo ${'+'}; // 20

@nikic
Copy link
Member

nikic commented Jun 4, 2016

Is there an RFC coming for this? I don't think this can go through as a "bug fix"...

If we're going to support this here, there's a bunch of other places that currently only support simple variables, in particular catch clauses, function parameters and static variables. Should we support ${} syntax there as well? If not, where do we draw the line?

@haskellcamargo
Copy link
Author

Well, I believe we can expose our arguments better in a RFC. However, I'll need to get karma for that. I've mailed internals mail list last year and got no answer. Could you check it, please?

@nikic
Copy link
Member

nikic commented Jun 6, 2016

Do you have a link to your mail handy?

@haskellcamargo
Copy link
Author

Do you mean my e-mail? marcelocamargo@linuxmail.org. My user on php.net is haskellcamargo.

@nikic
Copy link
Member

nikic commented Jun 6, 2016

You mentioned that you mailed internals last year for RFC karma, but I couldn't find the mail. In any case I can't give out karma anyway, maybe @Tyrael can look into it?

@haskellcamargo haskellcamargo changed the title Add support for dynamic variable names in function scope [RFC] Add support for dynamic variable names in function scope Jun 20, 2016
@nikic nikic added the RFC label Jul 13, 2016
@onlurking
Copy link

No update on this yet?

@marcioAlmada
Copy link
Contributor

/pings @Tyrael again 😄

@haskellcamargo
Copy link
Author

haskellcamargo commented Nov 2, 2016

This PR has almost 6 months. :')
The little baby is growing and becoming a lil' child 🎉 🎉 🎉
I'll make a party when it reaches 1 year!

image

@marcioAlmada
Copy link
Contributor

marcioAlmada commented Nov 2, 2016

@haskellcamargo It seems your request got lost in the pipelines (this happened to my first attempt). How about asking for RFC karma again on internals? Or try the IRC channel, it's faster there.

@onlurking
Copy link

Sadly, no reponse yet, i'd love to see at least some feedback on this one.

@sgolemon
Copy link
Member

I sent a ping on list http://news.php.net/php.internals/98604

In the mean time, how about a gist based RFC? It'll get the conversation started.

@bjori
Copy link
Member

bjori commented May 2, 2017

heh. I don't know what happened to all the wiki admins.
I've added you (haskellcamargo) to the rfc group.

@cmb69
Copy link
Member

cmb69 commented Aug 2, 2018

@haskellcamargo Are you still interested in this feature? If so, please start the RFC process (I can confirm that the Wiki user haskellcamargo has RFC karma).

@cmb69
Copy link
Member

cmb69 commented Nov 30, 2018

@haskellcamargo ping!

@cmb69
Copy link
Member

cmb69 commented Jan 23, 2019

Since there has been no progress for quite some time, I'm closing this PR. Please re-open, if an RFC is available.

@cmb69 cmb69 closed this Jan 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants