php.net |  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
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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-23 10:05 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip


 [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.

thanks!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC