FAQ
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

Search Discussions

  • Sean Coates at Aug 6, 2005 at 1:50 pm

    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
  • Rasmus Lerdorf at Aug 6, 2005 at 1:56 pm

    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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupphp-internals @
categoriesphp
postedAug 6, '05 at 12:31p
activeAug 6, '05 at 1:56p
posts3
users3
websitephp.net

People

Translate

site design / logo © 2022 Grokbase