Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107280 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 91490 invoked from network); 21 Sep 2019 14:31:26 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 21 Sep 2019 14:31:26 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id D4D442D200B for ; Sat, 21 Sep 2019 05:09:34 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp3.php.net X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Virus: No Received: from mail-oi1-x235.google.com (mail-oi1-x235.google.com [IPv6:2607:f8b0:4864:20::235]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp3.php.net (Postfix) with ESMTPS for ; Sat, 21 Sep 2019 05:09:34 -0700 (PDT) Received: by mail-oi1-x235.google.com with SMTP id x3so4004426oig.2 for ; Sat, 21 Sep 2019 05:09:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=pG4jY2cPgSuGzYBo5oqFZ3qcIzBSOmMF/ht9i2Fimvc=; b=bnpNtDEtUpXfAWq5fIzPS0mbaGc/8z2NA//j346d78BUrD3/5E/QWq2083DFR6tVfm fYAjZb1XBhViZAMUri7dhemxXyoy/gp4U9Uzpji/bhEZMmBQ1WCwCn7CWX6B2BxyqWa8 DiDPSV01vDbV30tX8SKAMHs2k9212xRFz1ruw2ecZgeVzJE7EqBLnGmzOtnnFzHJWUfY OrZ8a28v2gHz2O8hSOKwbWGf+p6JMQmAzsfTEHNbZ45AyeLRnpNOZ0J0iG0BDbdqQjuT BspeUNnvalzdAO09oB6y2LWenDadJ50GXZQwOY4aAaIOl6dEaLhy9nQKPsxb2vfzvK81 lFwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=pG4jY2cPgSuGzYBo5oqFZ3qcIzBSOmMF/ht9i2Fimvc=; b=q7Olj7fIWNU1c775GAp03w4pxF6Wm+EGWlLA8oabDhec/i8V2r6J7YrpmL11txFTar USby2SOLxGo4brnpxvLL5HfPMkAvWJpDQu1MjKL8TzOlWYBeMjYAxV5ehf+UM8HOd6jk I3N4mEoLj8IcTDlMRr33g5SkFS2m+HOvPPJ7nPvA6fteYVR9obh3P9cvJ3Rcfo5Yz4ZH lD5a0CDdKKMG0dCc2N4SBRXmx410Mj58a5Q0ziF0nT2YXk1NJ38CSfdA28cPKKHtAiBs ZOTol2OjnEhVs8ceTH3rSus/QUoP+6wQA5ydH8RKu6MCGJwh8uKs0BMeaWNULK22vJT+ 3GqA== X-Gm-Message-State: APjAAAVe/E2MNjeGnrPbph3GcjLz1u0wsxpL68A+5YZQSO71rHC4FVd1 t8iYGFwPg/2bTRkRzcWeyBeVmLXniP6JVJKzZRc= X-Google-Smtp-Source: APXvYqwqRBJdrLFO72f2omvzGTDqvAq+DpNy0lpYvXzoLkyuALcuod0vAQTwhCuf3kd+739eaiSQgb3zwZppHiaUZrs= X-Received: by 2002:aca:5f46:: with SMTP id t67mr6787506oib.42.1569067773627; Sat, 21 Sep 2019 05:09:33 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 21 Sep 2019 19:09:21 +0700 Message-ID: To: Nikita Popov Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000046938105930f0fbd" X-Envelope-From: Subject: Re: [PHP-DEV] Question about `global` variable declaration From: webdevxp.com@gmail.com (Kosit Supanyo) --00000000000046938105930f0fbd Content-Type: text/plain; charset="UTF-8" I understand your point but inconsistency in my sense is syntactical By comparing to other declaration syntax like `var`, `static`, 'public` an others. They allow only T_VARIABLE but `global` is different. And there's another way to archive the same goal through `$GLOBALS`, that's why I see it as inconsistency. P.S. I wrote this not because I want to convince you to make any change but just to explain my point. Cheers On Sat, Sep 21, 2019 at 6:24 PM Nikita Popov wrote: > On Sat, Sep 21, 2019 at 12:58 PM Kosit Supanyo > 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 >> wrote: >> >>> On Sat, Sep 21, 2019 at 11:56 AM Kosit Supanyo >>> 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 >>> >> --00000000000046938105930f0fbd--