php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #31542 eval() terminates PHP on fatal error instead of returning false
Submitted: 2005-01-13 18:14 UTC Modified: 2005-01-24 14:16 UTC
From: jcmailtrap-php at yahoo dot ca Assigned:
Status: Closed Package: Documentation problem
PHP Version: 5.0.3 OS: RHEL3
Private report: No CVE-ID: None
 [2005-01-13 18:14 UTC] jcmailtrap-php at yahoo dot ca
Description:
------------
When a fatal error is caused by attempting to call a method on an non-object or non-existing variable, eval() throws a fatal error which terminates the script instead of returning false as stated in the doc.

Reproduce code:
---------------
$result = eval('$nosuchobject->method();');
echo "done eval\n";
if ($result===false) {
    echo "error correctly returned\n";
}


Expected result:
----------------
Notice: Undefined variable: nosuchobject 
Fatal error: Call to a member function method() on a non-object

done eval
error correctly returned


Actual result:
--------------
Notice: Undefined variable: nosuchobject 
Fatal error: Call to a member function method() on a non-object


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-14 05:19 UTC] jed@php.net
Don't all E_ERRORs do this?
 [2005-01-14 05:26 UTC] sniper@php.net
Fatal errors are...tadaa..FATAL! As such -> exit.
No bug here.

 [2005-01-14 05:31 UTC] jcmailtrap-php at yahoo dot ca
Well, in eval()'s manual page, it is stated:
In case of a fatal error in the evaluated code, eval() returns FALSE.

Obviously eval() did not return FALSE in this case because the script exited.
 [2005-01-14 05:39 UTC] sniper@php.net
So the one who wrote the manual page made a mistake since
eval() isn't some magic thing that can override fatal errors..

 [2005-01-14 17:02 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

Changed to: "In case of a parse error in the evaluated code, eval() returns FALSE."
 [2005-01-17 08:24 UTC] derick@php.net
Jani, you're wrong. Eval is supposed not to throw a fatal error when the script passed to it is wrong. In case of a parse-error it does return false, and does not abort the script, where it normally would abort the script (with required that is). For things like calling an not existing method it will of course throw a fatal error.
 [2005-01-17 09:46 UTC] vrana@php.net
Derick, why you reopened this bug? What next should be documented?
 [2005-01-24 14:16 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

"In case of a fatal error in the evaluated code, the whole script exits."
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 19 14:00:02 2025 UTC