|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
Patcheserror.patch (last revision 2013-06-25 08:29 UTC by jwalton at m3hc dot com)Pull RequestsHistoryAllCommentsChangesGit/SVN commits
[2011-02-18 10:10 UTC] sht dot alien at gmx dot net
[2013-06-25 08:51 UTC] jwalton at m3hc dot com
[2017-12-23 12:35 UTC] nikic@php.net
[2017-12-23 12:35 UTC] nikic@php.net
-Status: Open
+Status: Closed
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 08:00:02 2025 UTC |
Description: ------------ Exceptions thrown by standard PHP classes are handled inconsistently to user defined exceptions, but should not. An internal exception, like the one thrown by DateTime::__construct() when supplying and invalid date string (like '9999-11-33') also trigger a E_WARNING. User defined Exceptions do not trigger an additional E_WARNING. If you create a custom error handler which converts all PHP errors to exceptions, catching internal exceptions inline therefore throws another Exception in the custom error handler, making it impossible to really catch the Exception. REQUEST: Both exception types should work consistently likewise, preferrably without triggering an E_WARNING. Or there should be means to distinguish an error triggered by an internal exception from an actual error and provide data if the exception was already handled/catched. Test script: --------------- <?php ////////////////////////////////// // PHP INTERNAL EXCEPTION: ////////////////////////////////// register_shutdown_function('shutdown'); $time = '9999-11-33'; // obviously invalid ;-) $timeZone = new DateTimeZone('UTC'); try { $dateTime = new DateTime($time, $timeZone); } catch (Exception $e) { var_dump('Exception:', $e->getMessage()); } echo 'END' . PHP_EOL; function shutdown() { $error = error_get_last(); var_dump('Error ', @$error); } ?> <?php ////////////////////////////////// // USER DEFINED EXCEPTION: ////////////////////////////////// register_shutdown_function('shutdown'); try { throw new Exception('Foo Exception'); } catch (Exception $e) { var_dump('Exception:', $e->getMessage()); } echo 'END' . PHP_EOL; function shutdown() { $error = error_get_last(); var_dump('Error ', @$error); } ?> Expected result: ---------------- Output DateTime::__construct() exception: string(10) "Exception:" string(105) "DateTime::__construct(): Failed to parse time string (9999-11-33) at position 9 (3): Unexpected character" END string(6) "Error " array(4) { ["type"]=> int(2) ["message"]=> string(105) "DateTime::__construct(): Failed to parse time string (9999-11-33) at position 9 (3): Unexpected character" ["file"]=> string(67) "/home/jebner/Zend/workspaces/DefaultWorkspace7/sandbox/datetime.php" ["line"]=> int(8) } Output user defined exception: string(10) "Exception:" string(13) "Foo Exception" END string(6) "Error " NULL Actual result: -------------- Output DateTime::__construct() exception: string(10) "Exception:" string(105) "DateTime::__construct(): Failed to parse time string (9999-11-33) at position 9 (3): Unexpected character" END string(4) "Error " NULL } Output user defined exception: string(10) "Exception:" string(13) "Foo Exception" END string(6) "Error " NULL