|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39601 $GLOBALS superglobal and ${ {$ string variable parsing inconsistencies
Submitted: 2006-11-23 07:23 UTC Modified: 2006-11-24 03:51 UTC
From: jkloske at itee dot uq dot edu dot au Assigned:
Status: Closed Package: Strings related
PHP Version: 4.4.4 OS: Centos
Private report: No CVE-ID: None
 [2006-11-23 07:23 UTC] jkloske at itee dot uq dot edu dot au
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:
$READMEIFYOUCAN = "This line should appear twice!";
echo "${GLOBALS['READMEIFYOUCAN']}<br />";
echo "${GLOBALS['READMEIFYOUCAN']}<br />";

Expected result:
This line should appear twice!
This line should appear twice!
Since this isn't strictly the correct format of {$, I would also accept it printing out:
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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-23 10:05 UTC]
Please try using this CVS snapshot:
For Windows:

 [2006-11-24 03:51 UTC] jkloske at itee dot uq dot edu dot au
can't test linux, but windows php5 latest cvs snap doesn't suffer this problem.

perhaps it's just a problem with php4 or our older version of it that was fixed but not as a result of a bug report.

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Jun 07 11:03:40 2023 UTC