Req #67029 [Opn->Wfx]: feature-request: user defined superglobals
| From: | requinix@php.net | Date: | Sat, 05 Apr 2014 21:58:43 +0000 |
| Subject: | Req #67029 [Opn->Wfx]: feature-request: user defined superglobals | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-185118@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=67029&edit=1
ID: 67029
Updated by: requinix@php.net
Reported by: php at richardneill dot org
Summary: feature-request: user defined superglobals
-Status: Open
+Status: Wont fix
Type: Feature/Change Request
Package: Variables related
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Global variables are bad enough without letting developers make more of them. Especially when
there's no indication that a variable was defined globally. Maintenance and debugging is a
nightmare when you don't know where variables come from or how they got their values.
There are plenty of better mechanisms to share data across a script: registry pattern, singletons,
dependency injection, even static variables in classes...
Previous Comments:
------------------------------------------------------------------------
[2014-04-05 15:45:29] php at richardneill dot org
Description:
------------
When writing a complex web application, it is useful to put common configuration settings, strings,
database-connection resources, etc into an array, such as $APPLICATION.
However, it's then necessary to pull this in with "global $APPLICATION" into every
single function. This leads to uglier code.
Test script:
---------------
global $X; #wish: *push* X into the global scope.
$X = 42;
function testit () {
//global $X; #wish: not required to pull in $X here.
echo "X is $X";
}
function testit2 () {
//global $X; #... or here, or in 100 other places.
echo "X is $X";
}
testit();
testit2);
etc
Expected result:
----------------
It would be a useful enhancement to have one of the following:
* allow variables to be "pushed" into the global scope, rather than needing to be pulled
in by each function (i.e. declare the variable as global just once in the main body, rather than
every single time it's needed in a function).
* have a mechanism to create user-defined superglobals
(it's currently documented as being explicitly not allowed).
* have PHP pre-create an empty superglobal such as $_APP[] or $_USER[] which
is reserved for the user to do as he wishes.
Thanks for your time - I hope this suggestion is helpful.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=67029&edit=1