From: talex_id at o2 dot ru
Operating system: FreeBSD
PHP version: 4.3.8
PHP Bug Type: *General Issues
Bug description: Unable to access predifined variables as variable variables from
functions
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 bug report at http://bugs.php.net/?id=30345&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=30345&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=30345&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=30345&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=30345&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=30345&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=30345&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=30345&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=30345&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=30345&r=support
Expected behavior: http://bugs.php.net/fix.php?id=30345&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=30345&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=30345&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=30345&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=30345&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=30345&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=30345&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=30345&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=30345&r=float
MySQL Configuration Error: http://bugs.php.net/fix.php?id=30345&r=mysqlcfg