Edit report at https://bugs.php.net/bug.php?id=64153&edit=1

 ID:                 64153
 Updated by:         ni...@php.net
 Reported by:        rayro at gmx dot de
 Summary:            Creating own super globals
-Status:             Open
+Status:             Wont fix
 Type:               Feature/Change Request
 Package:            Class/Object related
 Operating System:   Irrelevant
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

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'];


Previous Comments:
------------------------------------------------------------------------
[2013-02-05 11:08:05] rayro at gmx dot de

Description:
------------
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:
---------------
<?php
static $_SUPER = array('foo' => 'bar');
class A
{
  function __construct()
  {
    echo($_SUPER['foo']);
  }
}
$obj = new A;
?>

Expected result:
----------------
string(3) "bar"

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


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=64153&edit=1

Reply via email to