Req #70244 [NEW]: creating superglobals (instead of static classes)

From: Date: Wed, 12 Aug 2015 12:08:17 +0000
Subject: Req #70244 [NEW]: creating superglobals (instead of static classes)
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-195150@lists.php.net to get a copy of this message
From: raat1979 at gmail dot com Operating system: Irellevant PHP version: Irrelevant Package: Variables related Bug Type: Feature/Change Request Bug description:creating superglobals (instead of static classes) 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 bug report at https://bugs.php.net/bug.php?id=70244&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70244&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70244&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70244&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=70244&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=70244&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=70244&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=70244&r=needscript Try newer version: https://bugs.php.net/fix.php?id=70244&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=70244&r=support Expected behavior: https://bugs.php.net/fix.php?id=70244&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=70244&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=70244&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=70244&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70244&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=70244&r=dst IIS Stability: https://bugs.php.net/fix.php?id=70244&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=70244&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=70244&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=70244&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=70244&r=mysqlcfg

« previous php.bugs (#195150) next »