ID:               39601
 Updated by:       [EMAIL PROTECTED]
 Reported By:      jkloske at itee dot uq dot edu dot au
-Status:           Open
+Status:           Feedback
 Bug Type:         Strings related
 Operating System: Centos
 PHP Version:      4.4.4
 New Comment:

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




Previous Comments:
------------------------------------------------------------------------

[2006-11-23 07:23:31] 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.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=39601&edit=1

Reply via email to