On Sat, Sep 21, 2019 at 12:58 PM Kosit Supanyo <webdevxp....@gmail.com>
wrote:

> Hi Dan and Internals
>
> Sorry  Dan, I forgot to include @Internals in previous reply so let me
> resend this again.
>
> Thank you for your reply. I see, but in that case it can be done with
> `$GLOBALS['abc']` right? So I don't see any benefits of allowing those
> forms, they're just another inconsistency that should not exist from the
> beginning. Yes, it does no harms but if nobody is really using it at all,
> is it good to remove this inconsistency? Or to make it really useful, why
> not just allow assignment like:
>
> global ${'abc'} = $someValue;
>
> Just my 2 cents.
>
> Regards
>

global $x; is a shorthand for $x =& $GLOBALS['x'];
global ${$x}; is a shorthand for ${$x} =& $GLOBALS[$x];

I don't think this syntax is inconsistent so long as PHP supports the
syntax ${$x} for variables in general.

The idea of a "global ${'abc'} = $someValue;" syntax doesn't seem to have a
relation to the ${} form in particular. A simple "global $var = $someValue"
is currently not supported either. That's because "global $var" simply
imports a global variable into the local scope. You would instead write
this as "global $var; $var = $someValue;".

Nikita


> On Sat, Sep 21, 2019 at 5:52 PM Nikita Popov <nikita....@gmail.com> wrote:
>
>> On Sat, Sep 21, 2019 at 11:56 AM Kosit Supanyo <webdevxp....@gmail.com>
>> wrote:
>>
>>> Hi Internals
>>>
>>> I'm working on my new proposals and I've found weirdness of global
>>> variable
>>> declaration in zend_language_parser.y.
>>>
>>> global_var:
>>>     simple_variable
>>>         { $$ = zend_ast_create(ZEND_AST_GLOBAL,
>>> zend_ast_create(ZEND_AST_VAR, $1)); }
>>> ;
>>>
>>> Above grammer allows something like this...
>>>
>>> global $$x;
>>> global $$$y;
>>> global $$$$z;
>>> global ${'abc'};
>>> global $$$$$$$$$${random_int(0, PHP_INT_MAX)};
>>>
>>> What's the propose of allowing this? And is there anyone out there
>>> knowing
>>> and using it? If not, should this be changed to allow only T_VARIABLE to
>>> make it consistent with `static` variable declaration?
>>>
>>> Regards
>>>
>>
>> Some grep results:
>>
>> sources/adodb/adodb-php/session/adodb-session.php
>> 676: global $$var;
>> 697: global $$var;
>>
>> sources/adodb/adodb-php/session/adodb-session2.php
>> 719: global $$var;
>> 740: global $$var;
>>
>> sources/adodb/adodb-php/session/old/adodb-cryptsession.php
>> 189: global $$var;
>>
>> sources/adodb/adodb-php/session/old/adodb-session.php
>> 300: global $$var;
>>
>> sources/adodb/adodb-php/session/old/adodb-session-clob.php
>> 269: global $$var;
>>
>> sources/wp-cli/wp-cli/php/WP_CLI/Runner.php
>> 1177: global ${$key};
>>
>>
>> sources/apache/log4php/src/main/php/pattern/LoggerPatternConverterSuperglobal.php
>> 71: global ${$this->name};
>>
>> We could deprecate this in favor of $GLOBALS, though as Dan said, the
>> motivation is not quite clear right now.
>>
>> Nikita
>>
>

Reply via email to