php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48177 Cannot wrap eval'd code with HTML
Submitted: 2009-05-07 10:13 UTC Modified: 2009-05-07 11:04 UTC
From: skds1433 at hotmail dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.2.9 OS: Windows Vista
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: skds1433 at hotmail dot com
New email:
PHP Version: OS:

 

 [2009-05-07 10:13 UTC] 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>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-07 10:22 UTC] skds1433 at hotmail dot com
Changed category, from 'Output Control'. Not really sure what this applies to.
 [2009-05-07 10:38 UTC] 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 11:04 UTC] skds1433 at hotmail dot com
Thank you for the explanation, that makes a lot of sense now that you mention it. Sorry for wasting your time.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 16 16:01:34 2025 UTC