Re: Question about `global` variable declaration

From: Date: Sat, 21 Sep 2019 14:25:53 +0000
Subject: Re: Question about `global` variable declaration
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-107281@lists.php.net to get a copy of this message
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 (#107281) next »