Bug #17605: variable variables and double quotes in HEREDOC strings
| From: | mbruggem at usal dot es | Date: | Wed, 05 Jun 2002 09:04:29 +0000 |
| Subject: | Bug #17605: variable variables and double quotes in HEREDOC strings | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-9525@lists.php.net to get a copy of this message | ||
From: mbruggem@usal.es
Operating system: Winows NT
PHP version: 4.2.0
PHP Bug Type: Strings related
Bug description: variable variables and double quotes in HEREDOC strings
<?php
/*
This program demonstrates the behavior of variable variables
inside of HEREDOC strings which are later EVALuated.
SUMMARY: In HEREDOC strings without embeded double quotes variable
variables can be
interpolated by using EVAL. If there are embeded double quotes
in a HEREDOC
string variable variables are not (further) interpolated by the
EVAL function.
*/
$lBN = "\n<br>\n>>>\n";
$rBN = "\n<<<\n<br>\n";
$page_title = "More String tests";
$aString = "This is a string";
$aVariable = "aString";
$a_single_quoteVar = <<<EOD
<p>
This is part of a HERE_DOC which does not contain any double quotes:
</p>
<p>
<pre>
$$aVariable : a variable variable without any quotes
'$$aVariable' : a variable variable with single quotes
</pre>
</p>
EOD;
$a_double_quoteVar = <<<EOD
<p>
This is part of a HERE_DOC which does contain double quotes:
</p>
<p>
<font color='red'>
<b>NOTE</b>: The variable variable do not work in any of the
cases where previously
the variable variable had worked in single quotes and without
quotes.
</font>
</p>
<pre>
$$aVariable : a variable variable with no quotes
'$$aVariable' : a variable variable with single quotes
"$$aVariable" : a variable variable with double quotes
</pre>
</p>
EOD;
$a_extra_quoteVar = <<<EOD
<p>
This is part of a HERE_DOC which does not contain double quotes aroung
the variables
but does have some "extra" double quotes - i.e: quotes that do not
contain variables
but just happen to exist inside the string.
</p>
<p>
<font color='red'>
<b>NOTE</b>: The mere presense of double quotes inside the string
is sufficient
to cause the variable variable to stop working.
</font>
</p>
<p>
'$$aVariable' : a Variable as a variable variable with single quotes
</p>
EOD;
$a_entity_quoteVar = <<<EOD
<p>
This is part of a HERE_DOC which does contain <b>entity</b> double
quotes. It can be used
as a work around:
</p>
<p>
<pre>
'$$aVariable' : a Variable as a variable variable with single quotes
"$$aVariable" : a Variable as a variable variable with entity
double quotes
</pre>
</p>
EOD;
/*
// Uncomment this block to see that all of the pre-EVAL states of the
variable variable are the same.
echo $a_single_quoteVar;
echo $a_double_quoteVar;
echo $a_extra_quoteVar;
echo $a_entity_quoteVar;
*/
eval ("\$a_single_quoteVar = \"$a_single_quoteVar\";");
eval ("\$a_double_quoteVar = \"$a_double_quoteVar\";");
eval ("\$a_extra_quoteVar = \"$a_extra_quoteVar\";");
eval ("\$a_entity_quoteVar = \"$a_entity_quoteVar\";");
$a_entity_quoteVar = ereg_replace('"', '"', $a_entity_quoteVar);
$page_body = $lBN . $a_single_quoteVar . $rBN
. $lBN . $a_double_quoteVar . $rBN
. $lBN . $a_extra_quoteVar . $rBN
. $lBN . $a_entity_quoteVar . $rBN;
// eval ("\$page_body = \"$page_body\";");
$page_template =<<<EOD
<html>
<head>
<title>$page_title</title>
<meta name="author" content="Martin Bruggeman">
<meta name="web master" content="Martin Bruggeman">
<meta name="copyright" content="© 2002 Me, myself, and
I">
<meta name="keywords" content="testing an exam system">
<style>
.main { margin: 2em; padding: 1em; }
</style>
</head>
<body>
<div CLASS='main'>
<p><a href="$PHP_SELF">come again</a></p>
$page_body
</div>
</body>
</html>
EOD;
print $page_template;
?>
--
Edit bug report at http://bugs.php.net/?id=17605&edit=1
--
Fixed in CVS: http://bugs.php.net/fix.php?id=17605&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=17605&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=17605&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=17605&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=17605&r=support
Expected behavior: http://bugs.php.net/fix.php?id=17605&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=17605&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=17605&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=17605&r=globals