feature request: user-defined superglobals

php.internals

Matthias Nothhaft

23 years ago
Hi Devs, is there a possibility to get a php function like declare_superglobal($_MYVAR); And then be able to use $_MYVAR as the existing superglobals ($_GET, $_SESSION, etc.) ??? I think, it would be a really nice feature! Is that a huge problem to get this work? Regards, Matthias

Andi Gutmans

23 years ago
Hi, This has been discussed in the past (see the archives of either this list or engine2). You'll have to manage with the existing ones. Andi At 09:21 PM 8/23/2003 +0200, Matthias Nothhaft wrote:

Matthias Nothhaft

23 years ago
Hi Andi Gutmans, you wrote:
> Hi, > > This has been discussed in the past (see the archives of either this > list or engine2). > You'll have to manage with the existing ones.
Very sad. Why is that? I took a look into the archive but couldn't find any reason!? Is it such a hard problem to get this work? I don't primary need this to access vars, but object methods (ok, objects are also vars...) of a large application framework I'm working on. I can't understand what the problem is. Ok, probably many people would misuse that for all there global vars - is that the argument against it? Is it a performance problem? But this 'feature' would help frameworks or huge applications to get shorter/easier access to there API ! $_MYFW->method_a(); is nicer than $GLOBALS['_MYFW']->method_a(); and also shorter for vars u're using very often... Regards, Matthias

Stefan Walk

23 years ago
On Sat, Aug 23, 2003 at 11:15:34PM +0200, Matthias Nothhaft wrote:
> $_MYFW->method_a(); is nicer than $GLOBALS['_MYFW']->method_a(); > and also shorter for vars u're using very often...
global $_MYFW; works fine there.
> Regards, > Matthias
-- Regards, Stefan Walk <swalk@prp.physik.tu-darmstadt.de>

Timm Friebe

23 years ago
On Sat, 2003-08-23 at 21:15, Matthias Nothhaft wrote: [...User-land superglobals...]
> $_MYFW->method_a(); is nicer than $GLOBALS['_MYFW']->method_a(); > and also shorter for vars u're using very often...
Use the singleton pattern: MYFW::getInstance()->method_a(); Global variables are evil. - Timm

Stefan Walk

23 years ago
On Sat, Aug 23, 2003 at 09:58:49PM +0000, Timm Friebe wrote:
> On Sat, 2003-08-23 at 21:15, Matthias Nothhaft wrote: > Use the singleton pattern: > MYFW::getInstance()->method_a();
Which doesn't work yet, to prevent misunderstandings...
> Global variables are evil.
Anything is evil if misused.
> > - Timm > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php
-- Regards, Stefan Walk <swalk@prp.physik.tu-darmstadt.de>

Zeev Suraski

23 years ago
At 01:08 24/08/2003, Stefan Walk wrote:
>On Sat, Aug 23, 2003 at 09:58:49PM +0000, Timm Friebe wrote: > > On Sat, 2003-08-23 at 21:15, Matthias Nothhaft wrote: > > Use the singleton pattern: > > MYFW::getInstance()->method_a(); > >Which doesn't work yet, to prevent misunderstandings...
Sure does. Zeev

Christian Schneider

22 years ago
Matthias Nothhaft wrote:
> declare_superglobal($_MYVAR);
Has one single superglobal $_APP (or $_USER or the like) already been discussed? (Sorry Andi, couldn't find it in this list and didn't find the 'engine2' list you were referencing at all). I second Matthias that some sort of user-controlled superglobal would be useful in frameworks, even if it was only one. Stefan Walk wrote:
> global $_MYFW;
I consider global the worst option ever as is has to be repeated inside every function. Redundant and bug prone. $GLOBALS['_MYFW'] is a bit better but very ugly and a pain to use. Timm Friebe wrote:
> MYFW::getInstance()->method_a();
Very clumsy. There's a reason why I'm not using Java! (-:C And no, it does _not_ work with PHP4 and excuse me, but PHP5 is far from being deployed at your friendly ISP. Don't fool yourselves, PHP4 will be around (and has to be supported by people writing PHP frameworks) for quite a while. An $_APP superglobal wouldn't allow multiple frameworks to coexist but I think there'd be enough uses to justify it. It'd for example allow me to turn $_REQUEST into an object, i.e. I could use $_APP->id instead of $_REQUEST['id'] which is so much nicer to use. And no, I don't use form variables with names that aren't valid PHP identifiers ;-). The abuse of $_SESSION for this was already condemned and I'd be uncomfortable to use $_REQUEST (or one of it's siblings) itself. Ok, ready to take the beating, - Chris