Req #60364 [Opn]: Implement ability to recover from fatal errors in eval()'d code
| From: | zyss at mail dot zp dot ua | Date: | Tue, 20 Dec 2011 15:05:47 +0000 |
| Subject: | Req #60364 [Opn]: Implement ability to recover from fatal errors in eval()'d code | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-165994@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=60364&edit=1
ID: 60364
User updated by: zyss at mail dot zp dot ua
Reported by: zyss at mail dot zp dot ua
Summary: Implement ability to recover from fatal errors in
eval()'d code
Status: Open
Type: Feature/Change Request
Package: *General Issues
Operating System: All
PHP Version: 5.3.8
Block user comment: N
Private report: N
New Comment:
> This could be solved more straight forward solved by making fatal errors an Exception in PHP
Yes, that would be ideal (this is how Java handles missing classes and methods and it works just
fine).
PHP borrowed from Java many features (classes, interfaces, "instanceof", ...), why not to
implement one more useful thing â not to kill scripts when something is missing?
Previous Comments:
------------------------------------------------------------------------
[2011-12-20 03:46:08] hanskrentel at yahoo dot de
Why specific for eval and not include and/or overal?
This could be solved more straight forward solved by making fatal errors an Exception in PHP, like
suggested in #28331 (which names eval in a comment as a use-case).
------------------------------------------------------------------------
[2011-11-23 13:27:35] zyss at mail dot zp dot ua
Description:
------------
Sometimes eval() is used as a way to execute PHP code within a shell (legal remote access for
debugging purposes) or to execute code compiled to PHP from higher-level scripting language or the
code stored in the database etc.
The common problem is that a call of non-existing function (or object instantiation) results in
termination of the whole script, not just eval'd code.
I think that it's not correct in such cases.
The obvious way to implement it would be adding flags to eval() function (as a second argument) one
of which could indicate that eval() should not terminate the script but just return an error or
raise an exception.
Such flags could be:
EVAL_FATAL_DIE // current behavior
EVAL_FATAL_ERROR // return FALSE
EVAL_FATAL_EXCEPTION // raise an exception of a predefined class (e.g. EvalException)
Test script:
---------------
try {
eval('non_existing_function()', EVAL_FATAL_EXCEPTION);
}
catch (EvalException $e) {
Logger::log('Error in eval\'d code', $e);
}
Expected result:
----------------
Exception being logged and script continued its execution.
Actual result:
--------------
Fatal error: Call to undefined function non_existing_function() in ... : eval()'d code(1) on
line 1
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=60364&edit=1