rfc:engine_exceptions_for_php7
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:engine_exceptions_for_php7 [2014/10/06 21:15] – nikic | rfc:engine_exceptions_for_php7 [2017/09/22 13:28] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 2: | Line 2: | ||
* Date: 2014-09-30 | * Date: 2014-09-30 | ||
* Author: Nikita Popov < | * Author: Nikita Popov < | ||
- | * Status: | + | * Status: |
- | * Proposed for: PHP 7 | + | |
- | * Patch: https:// | + | |
===== Introduction ===== | ===== Introduction ===== | ||
Line 13: | Line 11: | ||
<code php> | <code php> | ||
- | <?php | ||
- | |||
function call_method($obj) { | function call_method($obj) { | ||
$obj-> | $obj-> | ||
Line 28: | Line 24: | ||
</ | </ | ||
- | This RFC replaces the fatal error with an '' | + | This RFC replaces the fatal error with an '' |
- | + | ||
- | < | + | |
- | Fatal error: Uncaught exception ' | + | |
- | Stack trace: | + | |
- | #0 / | + | |
- | #1 {main} | + | |
- | thrown in / | + | |
- | </ | + | |
- | + | ||
- | Of course | + | |
<code php> | <code php> | ||
Line 50: | Line 36: | ||
</ | </ | ||
- | Note: This RFC mostly matches | + | If the exception is not caught, PHP will continue to throw the same fatal error as it currently does. |
===== Motivation ===== | ===== Motivation ===== | ||
Line 68: | Line 54: | ||
E_RECOVERABLE_ERROR | E_RECOVERABLE_ERROR | ||
// Parse error | // Parse error | ||
- | |||
E_PARSE | E_PARSE | ||
Line 200: | Line 185: | ||
restore_error_handler(); | restore_error_handler(); | ||
</ | </ | ||
+ | |||
+ | === Performance === | ||
+ | |||
+ | The ability to bypass recoverable fatal errors while still continuing execution in the same code path may cause performance issues in some cases. For example it is currently possible to completely ignore argument type hints with an error handler. As such a JIT compiler may not be able to make strong assumptions about the types of type hinted parameters. | ||
==== Solution: Exceptions ==== | ==== Solution: Exceptions ==== | ||
Line 219: | Line 208: | ||
* It is now allowed to use exceptions in the engine. | * It is now allowed to use exceptions in the engine. | ||
- | * Existing errors of type '' | + | * Existing errors of type '' |
* It is discouraged to introduce new errors of type '' | * It is discouraged to introduce new errors of type '' | ||
- | The patch attached to this RFC already converts a large number of fatal and recoverable fatal errors to exceptions. It also converts parse errors to exceptions (there's only one of those). | + | In order to avoid updating many tests the current error messages will be retained if the engine/ |
+ | |||
+ | The patch attached to this RFC already converts a large number of fatal and recoverable fatal errors to exceptions. It also converts parse errors to exceptions. | ||
+ | |||
+ | ==== Hierarchy ==== | ||
+ | |||
+ | There is some concern that by extending '' | ||
+ | |||
+ | < | ||
+ | BaseException (abstract) | ||
+ | +- EngineException | ||
+ | +- ParseException | ||
+ | +- Exception | ||
+ | +- ErrorException | ||
+ | +- RuntimeException | ||
+ | +- ... | ||
+ | +- ... | ||
+ | </ | ||
+ | |||
+ | As such engine/ | ||
+ | |||
+ | Whether such a hierarchy (with a new '' | ||
===== Potential issues ===== | ===== Potential issues ===== | ||
Line 260: | Line 270: | ||
$result = eval($code); | $result = eval($code); | ||
} catch (\ParseException $exception) { | } catch (\ParseException $exception) { | ||
- | // Handler | + | // Handle |
} | } | ||
- | </ | ||
- | |||
- | ==== catch-all blocks in existing code ==== | ||
- | |||
- | As '' | ||
- | |||
- | ==== Cluttered error messages ==== | ||
- | |||
- | Going back to the code-sample from the introduction, | ||
- | |||
- | < | ||
- | Fatal error: Call to a member function method() on a non-object in / | ||
- | </ | ||
- | |||
- | With this RFC the error changes into an uncaught exception: | ||
- | |||
- | < | ||
- | Fatal error: Uncaught exception ' | ||
- | Stack trace: | ||
- | #0 / | ||
- | #1 {main} | ||
- | thrown in / | ||
- | </ | ||
- | |||
- | The uncaught exception message provides more information, | ||
- | |||
- | I think it would be nice to make those messages a bit cleaner (for all exceptions). The following adjustment is simple to do and seems more readable to me: | ||
- | |||
- | < | ||
- | Fatal error: Uncaught EngineException: | ||
- | Stack trace: | ||
- | #0 / | ||
- | #1 {main} | ||
- | thrown in / | ||
- | </ | ||
- | |||
- | Additional improvement (like removing the '' | ||
- | |||
- | < | ||
- | Uncaught EngineException: | ||
- | Stack trace: | ||
- | #0 / | ||
- | #1 {main} | ||
</ | </ | ||
Line 337: | Line 304: | ||
===== Patch ===== | ===== Patch ===== | ||
- | A preliminary | + | A patch for this RFC is available at https:// |
The patch introduces basic infrastructure for this change, replaces '' | The patch introduces basic infrastructure for this change, replaces '' | ||
- | The patch does not yet contain all necessary test updates and is also not yet thoroughly tested. | + | To simplify porting to exceptions it is possible to throw engine exceptions by passing an additional '' |
+ | |||
+ | < | ||
+ | - zend_error_noreturn(E_ERROR, | ||
+ | + zend_error(E_EXCEPTION | E_ERROR, " | ||
+ | + FREE_UNFETCHED_OP1(); | ||
+ | + HANDLE_EXCEPTION(); | ||
+ | </ | ||
+ | |||
+ | The current | ||
===== Vote ===== | ===== Vote ===== | ||
+ | The primary vote decides if the proposal as outlined in the RFC is accepted and requires a 2/3 majority. | ||
+ | |||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
+ | |||
+ | The secondary vote decides whether or not a '' | ||
+ | |||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
+ | |||
+ | Voting started on 2015-02-23 and ends on 2015-03-08. |
rfc/engine_exceptions_for_php7.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1