Bug #78505 [Com]: casting stdClass to string now unrecoverable fatal error

From: Date: Fri, 06 Sep 2019 12:12:51 +0000
Subject: Bug #78505 [Com]: casting stdClass to string now unrecoverable fatal error
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-222602@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78505&edit=1 ID: 78505 Comment by: kontakt at beberlei dot de Reported by: phofstetter at sensational dot ch Summary: casting stdClass to string now unrecoverable fatal error Status: Open Type: Bug Package: *General Issues Operating System: macOS, Debian Linux PHP Version: 7.4.0RC1 Block user comment: N Private report: N New Comment: For a workaround - and potentially the actual "fix", you should catch (Error $e) directly in your code instead of relying on the error handler. Previous Comments: ------------------------------------------------------------------------ [2019-09-06 12:02:58] 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 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=78505&edit=1

« previous php.bugs (#222602) next »