# custom superglobals

- Thread: https://externals.io/message/17558
- Original archive: https://news-web.php.net/php.internals/17558
- Started by Ron Korving on 2005-08-06T12:30:57+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #17558 — Ron Korving — 2005-08-06T12:30:57+00:00

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

Hi,

Wouldn't it be a good feature to have users create their own superglobals? I
think it would be good for at least two reasons (rather similar though):

- Application settings can be stored in such a global, so that objects can
use them without needing the information passed to functions or using the
rather ugly "global" statement.

- A singleton constructor could use it to grab information. Normally, in my
own database abstraction layer, I would create the database object and pass
the constructor information on where to connect. I don't want to implement
my DB class to open a file to read connection information and I don't want
it to use the "global" statement. This presents a problem if I want it to be
a singleton object, because I'd need the information everytime I call
getInstance() which is of course not really an option. Personally, I don't
consider using a superglobal from within the constructor an ugly practice.

Ron

---

## #17559 — Sean Coates — 2005-08-06T13:49:59+00:00

URL: https://externals.io/message/17558#17559 · In reply to: #17558

Ron Korving wrote:
> Wouldn't it be a good feature to have users create their own superglobals?

I realize that you're probably talking about creating custom 
superglobals in the PHP core, but you might want to look at Sara's 
Runkit project (in PECL). It allows custom superglobals.

http://pecl.php.net/runkit
(beware the segfaults (-; )

S

---

## #17560 — Rasmus Lerdorf — 2005-08-06T13:56:49+00:00

URL: https://externals.io/message/17558#17560 · In reply to: #17558

Ron Korving wrote:
> Hi,
> 
> Wouldn't it be a good feature to have users create their own superglobals? I
> think it would be good for at least two reasons (rather similar though):
> 
> - Application settings can be stored in such a global, so that objects can
> use them without needing the information passed to functions or using the
> rather ugly "global" statement.
> 
> - A singleton constructor could use it to grab information. Normally, in my
> own database abstraction layer, I would create the database object and pass
> the constructor information on where to connect. I don't want to implement
> my DB class to open a file to read connection information and I don't want
> it to use the "global" statement. This presents a problem if I want it to be
> a singleton object, because I'd need the information everytime I call
> getInstance() which is of course not really an option. Personally, I don't
> consider using a superglobal from within the constructor an ugly practice.

That's what $GLOBALS is for.

-Rasmus
