Bug #72948 [Asn->Csd]: Uncatchable "Catchable" fatal error for class to string conversions

From: Date: Tue, 06 Sep 2016 12:16:43 +0000
Subject: Bug #72948 [Asn->Csd]: Uncatchable "Catchable" fatal error for class to string conversions
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-203834@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=72948&edit=1 ID: 72948 Updated by: cmb@php.net Reported by: fredrik at neam dot se Summary: Uncatchable "Catchable" fatal error for class to string conversions -Status: Assigned +Status: Closed Type: Bug Package: Scripting Engine problem PHP Version: 7.1.0beta3 Assigned To: nikic Block user comment: N Private report: N New Comment: Automatic comment on behalf of cmbecker69@gmx.de Revision: http://git.php.net/?p=php-src.git;a=commit;h=727b422ad91f0d767d8f0fb3951b89fa9da8668f Log: Fix #72948: Uncatchable &quot;Catchable&quot; fatal error for class to string conversions Previous Comments: ------------------------------------------------------------------------ [2016-08-26 18:46:15] nikic@php.net 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. ------------------------------------------------------------------------ [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

« previous php.bugs (#203834) next »