Bug #72948 [Csd]: Uncatchable "Catchable" fatal error for class to string conversions
| From: | requinix@php.net | Date: | Fri, 31 Dec 2021 16:09:22 +0000 |
| Subject: | Bug #72948 [Csd]: Uncatchable "Catchable" fatal error for class to string conversions | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-238683@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: requinix@php.net
Reported by: fredrik at neam dot se
Summary: Uncatchable "Catchable" fatal error for class to
string conversions
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:
@cryptomister99: This is documented in the 7.4 migration guide.
https://www.php.net/manual/en/migration74.new-features.php
> Allow exceptions from __toString()
> Throwing exceptions from __toString() is now permitted. Previously this resulted
> in a fatal error. Existing recoverable fatal errors in string conversions have
> been converted to Error exceptions.
Previous Comments:
------------------------------------------------------------------------
[2021-12-31 15:49:05] cryptomister99 at gmail dot com
Since PHP 7.4 this has changed, so now it throws an exception that is catched in the (try) catch
block, and not catched in the user error handler (using set_error_handler).
Is there an updated documentation about all of this? I've seen other odd cases, and I've
noticed that since PHP 7.4 there have been important changes related to react for "fatal
errors".
------------------------------------------------------------------------
[2016-10-17 10:08:43] bwoebi@php.net
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 "Catchable" fatal error for class to string
conversions
------------------------------------------------------------------------
[2016-09-06 12:16:42] cmb@php.net
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 "Catchable" fatal error for class to string
conversions
------------------------------------------------------------------------
[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>
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=72948
--
Edit this bug report at https://bugs.php.net/bug.php?id=72948&edit=1