Edit report at https://bugs.php.net/bug.php?id=63137&edit=1
ID: 63137
Comment by: valentiny510 at yahoo dot es
Reported by: valentiny510 at yahoo dot es
Summary: Allow custom GLOBAL variables
Status: Open
Type: Feature/Change Request
Package: Variables related
Operating System: XP
PHP Version: 5.4.7
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2012-09-22 08:23:36] 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 --
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63137&edit=1