# feature request: user-defined superglobals

- Thread: https://externals.io/message/4147
- Original archive: https://news-web.php.net/php.internals/4147
- Started by Matthias Nothhaft on 2003-08-23T19:21:13+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #4147 — Matthias Nothhaft — 2003-08-23T19:21:13+00:00

URL: https://externals.io/message/4147#4147

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

---

## #4149 — Andi Gutmans — 2003-08-23T20:18:15+00:00

URL: https://externals.io/message/4147#4149 · In reply to: #4147

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:
>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

---

## #5491 — Christian Schneider — 2003-11-16T11:26:05+00:00

URL: https://externals.io/message/4147#5491 · In reply to: #4147

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
