Re: Question about `global` variable declaration

From: Date: Sat, 21 Sep 2019 15:18:10 +0000
Subject: Re: Question about `global` variable declaration
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-107282@lists.php.net to get a copy of this message
> > Unlike var, public, static and others - 'global' is not a declaration of > class structure, but a way to access global variables. I know it is not and I think almost everyone knows that. As I said, I came up with this by comparing to other declarations syntactically not functionally, it is inconsistent in that way. I don't know how many PHP developers out there know global can take variable variables but I my guess is, very very little because there's no information about this behavior of global in PHP manual https://www.php.net/manual/en/language.variables.scope.php and I'd never seen those forms of global in any projects/articles before. Cheers On Sat, Sep 21, 2019 at 9:26 PM Zeev Suraski <zeev@php.net> wrote: > On Sat, Sep 21, 2019 at 3:09 PM Kosit Supanyo <webdevxp.com@gmail.com> > wrote: > >> 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. >> > > Even though we're dealing with archeology here - this really isn't an > inconsistency but intended behavior. > Unlike var, public, static and others - 'global' is not a declaration of > class structure, but a way to access global variables. In the same way it > sometimes makes sense to access variables indirectly ($$foo), it may > sometimes make sense to access global variables indirectly (global $$foo). > It allows for both creation and access of global variables. It doesn't > sound very useful or practical to provide that ability for the creation of > dynamic class properties, which is why it's not available for > var/public/static/etc. > > Zeev >

« previous php.internals (#107282) next »