rfc:catchable-call-to-member-of-non-object
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:catchable-call-to-member-of-non-object [2014/04/26 16:37] – thekid | rfc:catchable-call-to-member-of-non-object [2017/09/22 13:28] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: Catchable "call to a member function of a non-object" | ====== PHP RFC: Catchable "call to a member function of a non-object" | ||
- | * Version: | + | * Version: |
* Date: 2014-04-26 | * Date: 2014-04-26 | ||
* Author: Timm Friebe < | * Author: Timm Friebe < | ||
- | * Status: | + | * Status: |
* First Published at: https:// | * First Published at: https:// | ||
+ | |||
+ | **Note: This RFC has been superseded by the [[https:// | ||
===== Introduction ===== | ===== Introduction ===== | ||
Line 15: | Line 17: | ||
</ | </ | ||
- | If you want to run PHP as a webserver itself, fatal errors are problematic. For a long story on why you would want to do that in the first place, see http:// | + | One situation in which fatal errors are problematic is if you want to run PHP as a webserver itself. For a long story on why you would want to do that in the first place, see http:// |
+ | |||
+ | Other situtations are described in the [[https:// | ||
===== Proposal ===== | ===== Proposal ===== | ||
Line 40: | Line 44: | ||
This behavior is consistent with how type hints work. Framework authors can turn this into exceptions if they wish. | This behavior is consistent with how type hints work. Framework authors can turn this into exceptions if they wish. | ||
- | ==== Example ==== | + | ==== Example: Exceptions |
The following error handler could be embedded into frameworks: | The following error handler could be embedded into frameworks: | ||
Line 63: | Line 67: | ||
</ | </ | ||
+ | ==== Example: Without exceptions ==== | ||
+ | This could be a way for people preferring not to use exceptions and instead to exit the script directly, but get a stacktrace instead of just the fatal error message: | ||
+ | |||
+ | <PHP> | ||
+ | set_error_handler(function($code, | ||
+ | echo "*** Error #$code: $message\n"; | ||
+ | debug_print_backtrace(); | ||
+ | exit(0xFF); | ||
+ | }, E_RECOVERABLE_ERROR); | ||
+ | |||
+ | $m= new some_db_model(); | ||
+ | $row= $m-> | ||
+ | $row-> | ||
+ | </ | ||
==== Differences from Past RFCs ==== | ==== Differences from Past RFCs ==== | ||
This proposal doesn' | This proposal doesn' | ||
+ | |||
+ | ==== Inner workings ==== | ||
+ | |||
+ | Taken this code: | ||
+ | |||
+ | <PHP> | ||
+ | function a($comparator) { | ||
+ | $result= $comparator-> | ||
+ | // ... | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | You can unwind this to something like: | ||
+ | |||
+ | function a($comparator) { | ||
+ | 1: ZEND_INIT_METHOD_CALL $comparator ' | ||
+ | 2: ZEND_SEND_VAL | ||
+ | 3: ZEND_SEND_VAL | ||
+ | 4: ZEND_DO_FCALL_BY_NAME | ||
+ | 5: ZEND_ASSIGN | ||
+ | // ... | ||
+ | } | ||
+ | |||
+ | The handling on checking whether the method is callable happends inside | ||
+ | the opline #1 ('' | ||
+ | checks its first argument (here: '' | ||
+ | or not. In case it's not, the following happens: | ||
+ | |||
+ | - A recoverable error is triggered. Should the script exit here, there' | ||
+ | - In case the script continues, all the oplines are skipped until we find the '' | ||
+ | - The return value is set to '' | ||
+ | - The control is handed back to the executor, which then continues with the '' | ||
+ | - The engine is again in full control; if an exception was raised by the handler, that leads to the known behavior. | ||
===== Other Impact ===== | ===== Other Impact ===== | ||
Line 94: | Line 145: | ||
* Also allowing to catch and handle other fatal errors | * Also allowing to catch and handle other fatal errors | ||
+ | |||
+ | ===== Vote ===== | ||
+ | Voting started 2014-06-29 and ended 2014-07-30. | ||
+ | |||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
+ | |||
===== References ===== | ===== References ===== | ||
Line 99: | Line 159: | ||
* PHP Bug [[https:// | * PHP Bug [[https:// | ||
* HHVM [[https:// | * HHVM [[https:// | ||
+ | * [[http:// | ||
+ | * [[rfc/ |
rfc/catchable-call-to-member-of-non-object.1398530275.txt.gz · Last modified: 2017/09/22 13:28 (external edit)