php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #36758 eval not behaving like in documantation
Submitted: 2006-03-16 12:00 UTC Modified: 2006-03-16 21:55 UTC
From: khan dot shadow at gmail dot com Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2006-03-16 12:00 UTC] khan dot shadow at gmail dot com
Description:
------------
" In case of a parse error in the evaluated code, eval() returns FALSE. In case of a fatal error in the evaluated code, the whole script exits."

Reproduce code:
---------------
$page  = 'for(\$i=0;\$i<=2;\$i++){?>';
$page .= '<b>test code</b>';
$page .= '<? } ?>';
'
$cad = $page;
$cad = @eval($cad)==false ? echo $cad : ob_get_contents();



Expected result:
----------------
$cad should be $cad='<b>test code</b><b>test code</b><b>test code</b>'

Actual result:
--------------
$cad is echod to the screen

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-03-16 12:12 UTC] mike@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

Then don't use the echo statement.
 [2006-03-16 16:10 UTC] colder@php.net
There are a lot of non-sense in your post:

1) variables don't have to be escaped inside single quotes, the evaluated code will result to a parse error.

2) you can't use echo in a return context, because echo is a language construct that doesn't behave like a function.

3) your eval() will always be evaluated as false : "As of PHP 4, eval() returns NULL unless return is called in the evaluated code".




 [2006-03-16 21:55 UTC] khan dot shadow at gmail dot com
never mind...problem solved :)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Nov 19 17:00:01 2025 UTC