Bug #72948 [Asn]: Uncatchable "Catchable" fatal error for class to string conversions
Edit report at https://bugs.php.net/bug.php?id=72948&edit=1
ID: 72948
Updated by: nikic@php.net
Reported by: fredrik at neam dot se
Summary: Uncatchable "Catchable" fatal error for class to
string conversions
Status: Assigned
Type: Bug
Package: Scripting Engine problem
PHP Version: 7.1.0beta3
Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
This case has been intentionally omitted, because throwing exceptions from string conversions is
ostensibly unsafe (in practice you can simply convert the recoverable fatal to an exception using an
error handler, so it's sort of a moot argument).
Btw, we should get rid of any references to "catchable" fatal errors (if they still exist)
in favor of "recoverable" fatal errors. Using "catchable" here is confusing as
they cannot be caught using catch blocks.
Previous Comments:
------------------------------------------------------------------------
[2016-08-26 17:28:12] cmb@php.net
> This results in confusion regarding whether or not PHP7's new
> ability to catch these fatal errors work or not.
The issue is not the catching of the exception, but rather that in
this case no exception is thrown at all; instead a classic
E_RECOVERABLE error is raised; otherwise you'd see a stack trace.
@nikic Has this case[1] been deliberately omitted, or has it just
been overlooked?
[1] <https://github.com/php/php-src/blob/PHP-7.1.0beta3/Zend/zend_operators.c#L889>
------------------------------------------------------------------------
[2016-08-26 13:48:53] fredrik at neam dot se
Removed operating system value since this is likely not OS-specific
------------------------------------------------------------------------
[2016-08-26 13:44:29] fredrik at neam dot se
Description:
------------
When attempting to convert a class to a string, the resulting "Catchable" fatal error is
not being caught.
This results in confusion regarding whether or not PHP7's new ability to catch these fatal
errors work or not. It turns out that some catchable fatal errors indeed can be caught, while some
don't, like the one being reported here.
This has been confirmed using the below test script against all active php and hhvm versions:
https://3v4l.org/GeNpF
Test script:
---------------
<?php
echo "PHP Version: " . PHP_VERSION . "\n";
try {
$v = new DateTime();
$v = (string) $v;
} catch (Error $e) {
echo "Caught 'Catchable fatal error' with message: " . $e->getMessage();
die();
}
echo "Did not catch 'Catchable fatal error'";
Expected result:
----------------
The Catchable fatal error should be caught
Actual result:
--------------
The Catchable fatal error is acting like a non-catchable fatal error
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=72948&edit=1
Thread (7 messages)