php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75954 E_RECOVERABLE_ERROR Not Caught
Submitted: 2018-02-13 02:27 UTC Modified: 2018-02-14 21:17 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: johnpaulwallway at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 7.0.27 OS: Linux: 14.04.5 LTS, Trusty Tahr
Private report: No CVE-ID: None
 [2018-02-13 02:27 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-02-13 09:39 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2018-02-13 09:39 UTC] 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-14 20:52 UTC] 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-14 21:17 UTC] 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 21:58 UTC] johnpaulwallway at gmail dot com
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)?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 15:01:28 2024 UTC