Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107279 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 83729 invoked from network); 21 Sep 2019 13:46:29 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 21 Sep 2019 13:46:29 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 5ED772D2023 for ; Sat, 21 Sep 2019 04:24:37 -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: X-Spam-Virus: No Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) (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 04:24:35 -0700 (PDT) Received: by mail-lf1-x131.google.com with SMTP id c195so6787243lfg.9 for ; Sat, 21 Sep 2019 04:24:35 -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=4w4d72/A/pSIUlme9UIH/Pz6w7fw3RrkfMizR/JW7iU=; b=mPk202J7XL7UGR5dUZb23sCd4t7FFxRJp3L+/ge0lDVq0K7p5xFEXCvC31dsdynjJM sIcGh2fkRWFb3f1VWRJ5HUMMaL3XdvsWdqiNQ/XzaqbtaTIouAkbtGPIUODbb9/WRi5P n69esdSGn15EuEKpe9rLKY8levazpx9WHKuKNHIwdh1MRs8809F/4UE4V+77z0xcIgtZ pqhPIN4vxSYZiUM0xidvqUS6CRBmXR9274rwZtSEr0ViAj6qXwbsNDl0lMtsSDhzG8xn sCkknAUG4FZx2fwTx+CiT7J1wIkRYSn3kBDYGAw/BtsMBZ2pY1hVvpgyd4EddkLT4b3y y11w== 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=4w4d72/A/pSIUlme9UIH/Pz6w7fw3RrkfMizR/JW7iU=; b=VPgb1LBxAJCn+55HWN+wAREaFCaHncUALISlr319ZGH8czkIROJxuig2PHQ8HiYnGl olU2l4zumwtuHKXxAfEo8hdKjxzh7mOJ8SSU6S8N/gTsIHGecxhTzDX6PhMDbKU6zJfP KpxarOBiy3ZEAguDckzW7oKUisXLFjwchAKR2B3mjvYDfv6xPA5bJzIZBEYoOnKtazpo bLYTuXBdDmzVulWdvYYn+Z0BSfUfeP4aFJa26OIxsgB3ec5rJHaC5Na3iOPhGyFCi8le XuwXwc141pL5sc+/dECMo1fqxbDNu40eU5HmcIMLq/n9U34PaozOPK/jx2fHoBVKZF2q BQRg== X-Gm-Message-State: APjAAAWkEUycAjBb8Q12rFf2Zialr44LZ+467cREuB7+NtwXvAtmkYjd 0cR7s9zoVVZ0wW+UyjrG1qQvxCezD/th43N5qQ0= X-Google-Smtp-Source: APXvYqzHR8lWFIN/CRZWtdsLhZl98A/bkIRl+EXn/bsCz88eNCUp1rGCqNcrXnRt+TzJ/GmEuHPhC0Gazn2fFIGtjnQ= X-Received: by 2002:ac2:44b9:: with SMTP id c25mr11898922lfm.112.1569065074425; Sat, 21 Sep 2019 04:24:34 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 21 Sep 2019 13:24:18 +0200 Message-ID: To: Kosit Supanyo Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000064043905930e6ede" X-Envelope-From: Subject: Re: [PHP-DEV] Question about `global` variable declaration From: nikita.ppv@gmail.com (Nikita Popov) --00000000000064043905930e6ede Content-Type: text/plain; charset="UTF-8" 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 >> > --00000000000064043905930e6ede--