|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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 --
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 03:00:01 2025 UTC |
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.