php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #63137 Allow custom GLOBAL variables
Submitted: 2012-09-22 08:23 UTC Modified: 2012-09-24 01:51 UTC
From: valentiny510 at yahoo dot es Assigned:
Status: Wont fix Package: Variables related
PHP Version: 5.4.7 OS: XP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: valentiny510 at yahoo dot es
New email:
PHP Version: OS:

 

 [2012-09-22 08:23 UTC] valentiny510 at yahoo dot es
Description:
------------
I think can be very usefull, sometimes, to be able to make a custom global variable, like languages, configs, etc.. and working just like $GLOBALS but only with the value/values assigned. I'm sure more than 75%-80% of the Php users will be agreed with this change.
Imagine and array with some translation strings:

$lang = array(
    'bla' => 'some nonsense talk',
    'blabla' => 'More nonsense talks');

and now the 'trick'.. some function to make 'global' the $lang:
make_global( $lang );

or even set in the php.ini some configuration like:
custom_globals = "lang, config, more, etc, bla, bla"

and now we can use it on global scope
function test() { return $lang['bla']; }

is a 'nicer' way than
function test() { return $GLOBALS['lang']['bla']; }
or
function test() { global $lang; return $lang['bla']; }


Test script:
---------------
-- none --

Expected result:
----------------
-- none --

Actual result:
--------------
-- none --

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-09-22 09:35 UTC] valentiny510 at yahoo dot es
I "flashed" the source code and founded the "zend_register_auto_global" and Im sure it can be done in the "php_startup_auto_globals" function or some other place, php_variables.c or zend.c just like:

    zend_register_auto_global("GLOBALS", sizeof("GLOBALS") - 1, 1, php_auto_globals_create_globals TSRMLS_CC);

but with our custom variable from php.ini for example.. just use ZEND_INI_ENTRY("custom_globals" ... and done ! :D
I know it can be done easy but now depend of you guys if you want to implement it or not.
 [2012-09-24 01:51 UTC] aharvey@php.net
-Status: Open +Status: Wont fix
 [2012-09-24 01:51 UTC] aharvey@php.net
If you really, desperately want this, you can use runkit, but not supporting custom autoglobals is a deliberate design decision: pervasive use of global variables is an anti-pattern.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 11:01:30 2024 UTC