|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #64153 Creating own super globals
Submitted: 2013-02-05 11:08 UTC Modified: 2013-02-05 14:14 UTC
From: rayro at gmx dot de Assigned:
Status: Wont fix Package: Class/Object related
PHP Version: Irrelevant OS: Irrelevant
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2013-02-05 11:08 UTC] rayro at gmx dot de
It would be a nice feature to create super globals at runtime like $_SERVER or $_SESSION without making the use of extensions like "runkit". I think it was runkit that enables this feature, or am i wrong?

Generally the "static" keyword is a good one to make this possible. It has currently no effect when using in global scope (no error, no warning, no notice).

What about to use static for defining super globals? I think it is self-explaining to the people out there...

Test script:
static $_SUPER = array('foo' => 'bar');
class A
  function __construct()
$obj = new A;

Expected result:
string(3) "bar"

Actual result:
Notice: Undefined variable: _SUPER in ... on line ...


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-02-05 14:14 UTC]
-Status: Open +Status: Wont fix
 [2013-02-05 14:14 UTC]
We definitely don't want to make using globals *easier*.

Apart from that, if you really want something like userland superglobals (for reasons that are elusive to me), you can simply use a shorter function alias and get more or less the same effect:

    function &_super() {
        return $GLOBALS['_SUPER'];

    // Usage:
    _super()['foo'] = 'bar';
    echo _super()['foo'];

Or with a small shortcut for access:

    function _super($offset = null) {
        if ($offset === null) {
            return $GLOBALS['_SUPER'];
        } else {
            return $GLOBALS['_SUPER'][$offset];

    // This way you can also write
    $foo = _super('foo');
    // instead of
    $foo = _super()['foo'];
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Jul 27 10:01:23 2021 UTC