#48177 [Bgs]: Cannot wrap eval'd code with HTML
| From: | skds1433 at hotmail dot com | Date: | Thu, 07 May 2009 11:04:22 +0000 |
| Subject: | #48177 [Bgs]: Cannot wrap eval'd code with HTML | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-136924@lists.php.net to get a copy of this message | ||
ID: 48177
User updated by: skds1433 at hotmail dot com
Reported By: skds1433 at hotmail dot com
Status: Bogus
Bug Type: Unknown/Other Function
Operating System: Windows Vista
PHP Version: 5.2.9
New Comment:
Thank you for the explanation, that makes a lot of sense now that you
mention it. Sorry for wasting your time.
Previous Comments:
------------------------------------------------------------------------
[2009-05-07 10:38:39] mattwil@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
eval() doesn't return anything but NULL unless a return statement is
used in the eval'd code (wouldn't work in this case with inline HTML
anyway, which gets echo'd immediately). You'd need to 1) echo "<pre>";
before the eval() call, 2) use eval('return "testing 123, a string, not
HTML...";'), or 3) use output buffering, etc.
------------------------------------------------------------------------
[2009-05-07 10:22:38] skds1433 at hotmail dot com
Changed category, from 'Output Control'. Not really sure what this
applies to.
------------------------------------------------------------------------
[2009-05-07 10:13:29] skds1433 at hotmail dot com
Description:
------------
For debugging purposes of a template system, I am trying to wrap the
output of an eval inside pre HTML tags. Oddly, the tags are simply being
appended.
PHP version: 5.2.9-2
Apache: 2.2.11
Reproduce code:
---------------
<?php
$buffer = 'testing 1 2 3, test test test test.
0123456789012345678901234567890123456789
012345678901234567890123456789
0123456789012345678901234567890123456789(<?php if
(isset($global[\'testing1\'])): ?>testing1<?php if
(isset($global[\'testing2\'])): ?> "testing2 extended"<?php if
(isset($global[\'testing3\'])): ?> "testing3 extended"<?php endif;
?><?php endif; ?><?php endif; ?>)0123456789
012345678901234567890123456789
<?php if (isset($global[\'loop1\']) && is_array($global[\'loop1\'])):
for($i=0;$i<count($global[\'loop1\']);$i++):
?><?=$global[\'loop1\'][\'var1\']?>
<?=$global[\'loop1\'][\'var2\']?>
<?php if ($global[\'loop1\'][\'showvar3\']):
?><?=$global[\'loop1\'][\'var3\']?><?php endif; ?><?php
endfor; endif;
?>
<?php if (isset($global[\'testing4\'])): ?>testing4<?php if
(isset($global[\'testing5\'])): ?> testing5<?php if
(isset($global[\'testing6\'])): ?> <this is file1><?php endif; ?><?php
endif; ?><?php endif; ?>';
$buffer = eval("?>".$buffer);
echo "<pre>".$buffer."</pre>";
?>
Expected result:
----------------
<pre>testing 1 2 3, test test test test.
0123456789012345678901234567890123456789
012345678901234567890123456789
0123456789012345678901234567890123456789()0123456789
012345678901234567890123456789
</pre>
Actual result:
--------------
testing 1 2 3, test test test test.
0123456789012345678901234567890123456789
012345678901234567890123456789
0123456789012345678901234567890123456789()0123456789
012345678901234567890123456789
<pre></pre>
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=48177&edit=1