Bug #17605 Updated: variable variables and double quotes in HEREDOC strings
| From: | sander@php.net | Date: | Fri, 07 Jun 2002 07:10:49 +0000 |
| Subject: | Bug #17605 Updated: variable variables and double quotes in HEREDOC strings | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-9722@lists.php.net to get a copy of this message | ||
ID: 17605
Updated by: sander@php.net
Reported By: mbruggem@usal.es
-Status: Open
+Status: Bogus
Bug Type: Strings related
Operating System: Winows NT
PHP Version: 4.2.0
New Comment:
You need to addslashes() the stuff before you eval() it.
Previous Comments:
------------------------------------------------------------------------
[2002-06-05 05:04:29] mbruggem@usal.es
<?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 this bug report at http://bugs.php.net/?id=17605&edit=1