#30345 [Opn->Bgs]: Unable to access predifined variables as variable variables from functions
| From: | derick@php.net | Date: | Thu, 07 Oct 2004 07:09:23 +0000 |
| Subject: | #30345 [Opn->Bgs]: Unable to access predifined variables as variable variables from functions | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-67232@lists.php.net to get a copy of this message | ||
ID: 30345
Updated by: derick@php.net
Reported By: talex_id at o2 dot ru
-Status: Open
+Status: Bogus
Bug Type: *General Issues
Operating System: FreeBSD
PHP Version: 4.3.8
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
You can't use the superglobals as variable variables, that's in the
manual.
Previous Comments:
------------------------------------------------------------------------
[2004-10-06 23:20:35] talex_id at o2 dot ru
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
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=30345&edit=1