|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-03-28 17:51 UTC] akorthaus at web dot de
Description:
------------
The ErrorException class bundled with PHP 5.1 does not work with Warnings/Fatal Errors produced by include() and require().
Reproduce code:
---------------
<?php
function ErrorsToExceptions($severity, $message) {
throw new ErrorException($message, 0, $severity);
}
set_error_handler('ErrorsToExceptions');
try {
include('./DOES_NOT_EXIST');
}
catch (Exception $e) {
echo get_class($e) . " catched!\n"
echo $e->getMessage();
}
?>
Expected result:
----------------
should throw an ErrorException and display $e->getMessage(), and should NOT display a PHP Warning.
Actual result:
--------------
Warning: main(): Failed opening './DOES_NOT_EXIST' for inclusion (include_path='.:') in /home/akorthaus/test/exc4.php on line 16
ErrorException catched!
include(./DOES_NOT_EXIST): failed to open stream: No such file or directory
if I replace "include" with "require", I get:
Fatal error: main(): Failed opening required './DOES_NOT_EXIST' (include_path='.:') in /home/akorthaus/test/exc4.php on line 14
if I replace "require" with "file_get_contents", I get:
ErrorException catched!
file_get_contents(./DOES_NOT_EXIST): failed to open stream: No such file or directory
That's what I'd expect to see from include() and require() too (ErrorException also works with other Fatal Errors!).
So include() seems to throw an ErrorException, but additionaly displays the PHP Warning, require only displays the PHP Fatal Error, and does not throw an Exception at all.
Is this intended? Is it somewhere documented how ErrorException works or should be used?
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Dec 06 09:00:02 2025 UTC |
I testet the latest 5.1-dev (5.1.3RC2-dev) snapshot now and everything works fine now - thanks a lot! Is there any documentation about ErrorException class? Is function ErrorsToExceptions($severity, $message) { throw new ErrorException($message, 0, $severity); } set_error_handler('ErrorsToExceptions'); correct / the recommended way? Is there a plan for an engine-level function to replace the code above, something like "use_exception_error_handler()"?