From: rquadling Operating system: Windows XP SP3 PHP version: 5.3.3 Package: Scripting Engine problem Bug Type: Bug Bug description:Variable variables can create invalid variables.
Description: ------------ It seems you can create a variable in $GLOBALS that is not accessible as a normal variable. I found this because I wanted to use variable variables to populate a nested array. Jim Lucas, in http://news.php.net/php.general/307392, comments that the use of eval() may be appropriate in the case. That aside, the entry that is created in $GLOBALS doesn't follow the rules for variable naming in http://docs.php.net/manual/en/language.variables.basics.php, namely that '[' and ']' are not valid variable names. I think this should have t least produced an E_WARNING. So, with all of that, I'm not sure if this is a bug or a documentation problem. I certainly think it is an edge case. Regards, Richard Quadling. Test script: --------------- <?php // Show all errors. error_reporting(-1); ini_set('display_errors', 1); // Expectation was to be able to create a deep array using variable variables. $a = 'b[1][2][3]'; $$a = 'Inaccessible?'; print_r($b); // Hide superglobals unset($_POST); unset($_GET); unset($_SESSION); unset($_FILES); unset($_COOKIE); unset($_SERVER); unset($argv); unset($argc); // Reveals inaccessible variable. var_dump($GLOBALS); Expected result: ---------------- Array ( [1] => Array ( [2] => Array ( [3] => Inaccessible? ) ) ) array(3) { ["GLOBALS"]=> *RECURSION* ["a"]=> string(10) "b[1][2][3]" ["b"]=> array(1) { [1]=> array(1) { [2]=> array(1) { [3]=> string(13) "Inaccessible?" } } } } Actual result: -------------- Notice: Undefined variable: b in - on line 5 array(4) { ["GLOBALS"]=> *RECURSION* ["a"]=> string(10) "b[1][2][3]" ["b[1][2][3]"]=> string(13) "Inaccessible?" ["php_errormsg"]=> string(21) "Undefined variable: b" } -- Edit bug report at http://bugs.php.net/bug.php?id=52576&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=52576&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=52576&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=52576&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=52576&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=52576&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=52576&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=52576&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=52576&r=needscript Try newer version: http://bugs.php.net/fix.php?id=52576&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=52576&r=support Expected behavior: http://bugs.php.net/fix.php?id=52576&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=52576&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=52576&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=52576&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=52576&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=52576&r=dst IIS Stability: http://bugs.php.net/fix.php?id=52576&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=52576&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=52576&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=52576&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=52576&r=mysqlcfg