From: jkloske at itee dot uq dot edu dot au Operating system: Centos PHP version: 4.4.4 PHP Bug Type: Strings related Bug description: $GLOBALS superglobal and ${ {$ string variable parsing inconsistencies
Description: ------------ The $GLOBALS superglobal when referenced inside a string using ${ (which is not strictly legal for PHP syntax, but which seems to work in most other situations) doesn't appear to exist (it evaluates to an empty string). As soon as $GLOBALS is referenced anywhere else in that same scope via either a direct expression or correctly inside a string using {$, even if this occurs after the incorrect reference using ${ in a string, all ${ references work. Very short example is included, to demonstrate, run as is, then run with the commented out line uncommented. I don't know that this is specifically a bug, but it does seem inconsistent and potentially problematic, and at the very least should be documented :) I'm really sorry to report this with my version of PHP (4.3.11) but I am not authorized to upgrade the version on the server, merely use it. Reproduce code: --------------- <?php $READMEIFYOUCAN = "This line should appear twice!"; echo "${GLOBALS['READMEIFYOUCAN']}<br />"; //$okayIwill = $GLOBALS['READMEIFYOUCAN']; echo "${GLOBALS['READMEIFYOUCAN']}<br />"; ?> Expected result: ---------------- A) This line should appear twice! This line should appear twice! B) Since this isn't strictly the correct format of {$, I would also accept it printing out: ${GLOBALS['READMEIFYOUCAN']} or perhaps some other strange PHP error type output or partially printed versions of that string. Actual result: -------------- <empty output> now uncomment the commented out line, and you see: This line should appear twice! This line should appear twice! This seems to indicate that as long as $GLOBALS is referenced outside a string, it works anywhere in the scope, even before it was first referenced. Note if you change either of the ${ inside the strings to {$ they both work, regardless of the order. -- Edit bug report at http://bugs.php.net/?id=39601&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=39601&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=39601&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=39601&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=39601&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=39601&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=39601&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=39601&r=needscript Try newer version: http://bugs.php.net/fix.php?id=39601&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=39601&r=support Expected behavior: http://bugs.php.net/fix.php?id=39601&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=39601&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=39601&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=39601&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=39601&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=39601&r=dst IIS Stability: http://bugs.php.net/fix.php?id=39601&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=39601&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=39601&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=39601&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=39601&r=mysqlcfg