php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #70244 creating superglobals (instead of static classes)
Submitted: 2015-08-12 12:08 UTC Modified: 2015-08-12 12:28 UTC
From: raat1979 at gmail dot com Assigned:
Status: Closed Package: Variables related
PHP Version: Irrelevant OS: Irellevant
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: raat1979 at gmail dot com
New email:
PHP Version: OS:

 

 [2015-08-12 12:08 UTC] 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();
}



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-08-12 12:28 UTC] raat1979 at gmail dot com
-Status: Open +Status: Closed
 [2015-08-12 12:28 UTC] raat1979 at gmail dot com
Found a Wontfix, see 
https://bugs.php.net/bug.php?id=67029
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Mon Sep 23 11:01:27 2019 UTC