|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2019-09-06 12:02 UTC] phofstetter at sensational dot ch
Description:
------------
In previous releases of PHP, casting instances of stdClass to string would raise an E_RECOVERABLE_ERROR, but in 7.4, this has changed to raise a E_ERROR fatal error.
I'm not entirely sure this increase of severity is entirely justified as catching fatal errors in production is still annoying and hard to get meaningful backtraces reported.
Test script:
---------------
<?php
set_error_handler(function($errno, $errstr, $errfile, $errline){
if((error_reporting() & $errno) === 0){
return true;
}
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
});
try {
(string)new stdClass;
} catch (ErrorException $e){
echo "caught\n";
}
Expected result:
----------------
"caught"
Actual result:
--------------
PHP Fatal error: Uncaught Error: Object of class stdClass could not be converted to string in /var/webapps/popscan/flupp.php:11
Stack trace:
#0 {main}
thrown in /var/webapps/popscan/flupp.php on line 11
Fatal error: Uncaught Error: Object of class stdClass could not be converted to string in /var/webapps/popscan/flupp.php:11
Stack trace:
#0 {main}
thrown in /var/webapps/popscan/flupp.php on line 11
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 17 16:00:01 2025 UTC |
it's catchable since PHP 7.0 try { } catch(Throwable $exception) { }