|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-10-07 09:09 UTC] derick@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Sun Feb 15 22:00:01 2026 UTC |
Description: ------------ PHP allows to use 'variable variables', constructions, like a $$name or ${$name}, where $name is a string. But if i try to access to $GLOBALS from function using this method ($$name or ${$name}, where $name = 'GLOBALS') i can't get it until i use its name at least one time into function (or method) body. It's enouth to add string $GLOBALS; (to 'touch') to make it visible from $$name construction. Another predifned variables are unaccessible even if i set some values to them into function body. See code examples (http://talex-id.o2.ru/devel/php/bugs/predefined_variables1.php.txt and http://talex-id.o2.ru/devel/php/bugs/predefined_variables2.php.txt). I used CLI version of PHP to test them. Reproduce code: --------------- <?php function f1() { echo 'GLOBALS, direct : ' . $GLOBALS . "\n"; echo 'GLOBALS, string in "{}" : ' . ${'GLOBALS'} . "\n"; } function f2() { $g_name = 'GLOBALS'; echo 'GLOBALS, string from variable in "{}" : ' . ${$g_name} . "\n"; } function f3() { $g_name = 'GLOBALS'; $GLOBALS; // Now we just have to touch GLOBALS variable to make it visible echo 'GLOBALS, toched, string from variable in "{}" : ' . ${$g_name} . "\n"; } f1(); echo "----------------------------------------------------\n"; f2(); echo "----------------------------------------------------\n"; f3(); ?> Expected result: ---------------- GLOBALS, direct : Array GLOBALS, string in "{}" : Array ---------------------------------------------------- GLOBALS, string from variable in "{}" : Array ---------------------------------------------------- GLOBALS, toched, string from variable in "{}" : Array Actual result: -------------- GLOBALS, direct : Array GLOBALS, string in "{}" : Array ---------------------------------------------------- GLOBALS, string from variable in "{}" : ---------------------------------------------------- GLOBALS, toched, string from variable in "{}" : Array