Req #70244 [Opn->Csd]: creating superglobals (instead of static classes)
| From: | raat1979 at gmail dot com | Date: | Wed, 12 Aug 2015 12:28:18 +0000 |
| Subject: | Req #70244 [Opn->Csd]: creating superglobals (instead of static classes) | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-195152@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70244&edit=1
ID: 70244
User updated by: raat1979 at gmail dot com
Reported by: raat1979 at gmail dot com
Summary: creating superglobals (instead of static classes)
-Status: Open
+Status: Closed
Type: Feature/Change Request
Package: Variables related
Operating System: Irellevant
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Found a Wontfix, see
https://bugs.php.net/bug.php?id=67029
Previous Comments:
------------------------------------------------------------------------
[2015-08-12 12:08:09] raat1979 at gmail dot com
Description:
------------
Currently there is no way to access global variables inside a function/class scope without using the
global keyword or $GLOBAL variable
As a result it is not possible to create for example a Config class that can easily be accessed
throughout an entire project
To have usable code one is forced to use static classes, retrofit some sort of static
constructor/init function and reference the config variables with for example Config::$defaultUser
If it where possible to register custom superglobal one could use an instance of these kind of
classes instead of a static class.
For php7 it is said that an Array Constant can be created which will create a partial solution.
Having the possibility to register a variable as a superglobal would greatly reduce the need for
static classes and/or other trickery.
An alternative would be to have the possibility of adding custom superglobals in php.ini but this
would be less practical
Test script:
---------------
// Suggested ways to use it on the php coding side
$config = Config::getInstance(); //singleTon
register_superglobal($config);
function X(){
$config->saveSettings();
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70244&edit=1