Bug #75954 [Com]: E_RECOVERABLE_ERROR Not Caught
Edit report at https://bugs.php.net/bug.php?id=75954&edit=1
ID: 75954
Comment by: johnpaulwallway at gmail dot com
Reported by: johnpaulwallway at gmail dot com
Summary: E_RECOVERABLE_ERROR Not Caught
Status: Not a bug
Type: Bug
Package: *General Issues
Operating System: Linux: 14.04.5 LTS, Trusty Tahr
PHP Version: 7.0.27
Block user comment: N
Private report: N
New Comment:
I misspoke, I understand that they are constants.
I meant, do you know of any documentation about the technical reasons why the error case
E_RECOVERABLE_ERROR cannot throw an Exception (which inherits from Error)?
Previous Comments:
------------------------------------------------------------------------
[2018-02-14 21:17:20] requinix@php.net
E_ERROR and E_RECOVERABLE_ERROR are not classes.
http://php.net/manual/en/errorfunc.constants.php
Here's an amazing resource to help you learn more:
https://www.google.com/search?q=php+error+handling
------------------------------------------------------------------------
[2018-02-14 20:52:00] johnpaulwallway at gmail dot com
nikic@php.net
I see. So, E_ERROR and E_RECOVERABLE_ERROR do not inherit from Throwable or from Error? Also, is
there any public information about the technical reasons these ERRORs cannot subclass Error?
Thanks
------------------------------------------------------------------------
[2018-02-13 09:39:39] nikic@php.net
Since PHP 7, fatal and recoverable fatal errors are used specifically in situations where throwing
an exception is not possible for technical reasons. These cases will be ported to throw Error
exceptions if and when the technical issues are resolved.
------------------------------------------------------------------------
[2018-02-13 02:27:12] johnpaulwallway at gmail dot com
Description:
------------
E_RECOVERABLE_ERROR halts the interpreter. While shutdown_function is called, one cannot handle
framework shutdown, responses, and logging in an appropriate manner.
E_RECOVERABLE_ERROR should be catchable by a catch( Throwable $t) or catch(ERROR
$e), and finally blocks _must_ be executed.
Test script:
---------------
<?php
$x = new stdClass();
try {
echo $x;
} catch (Throwable $t) {
echo "Yeah, we couldn't convert that to a string. Log error and respond to client's
request";
echo $t->__toString();
} finally {
echo "Seriously? I must be wrong";
}
Expected result:
----------------
Something like:
Yeah, we couldn't convert that to a string. Log error and respond to client's request.
E_RECOVERABLE_ERROR: Object of class stdClass could not be converted to string
Seriously? I must be wrong
Actual result:
--------------
PHP Catchable fatal error: Object of class stdClass could not be converted to string in
/tmp/foo.php on line 5
PHP Stack trace:
PHP 1. {main}() /tmp/foo.php:0
Catchable fatal error: Object of class stdClass could not be converted to string in /tmp/foo.php on
line 5
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75954&edit=1
Thread (5 messages)