|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-02-05 11:08 UTC] 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 ...
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 07:00:01 2025 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'];