From: akorthaus at web dot de Operating system: Linux 2.4.32 (gentoo) PHP version: 5.1.2 PHP Bug Type: Scripting Engine problem Bug description: ErrorException does not work with include/require errors
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? -- Edit bug report at http://bugs.php.net/?id=36896&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=36896&r=trysnapshot44 Try a CVS snapshot (PHP 5.1): http://bugs.php.net/fix.php?id=36896&r=trysnapshot51 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=36896&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=36896&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=36896&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=36896&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=36896&r=needscript Try newer version: http://bugs.php.net/fix.php?id=36896&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=36896&r=support Expected behavior: http://bugs.php.net/fix.php?id=36896&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=36896&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=36896&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=36896&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=36896&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=36896&r=dst IIS Stability: http://bugs.php.net/fix.php?id=36896&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=36896&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=36896&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=36896&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=36896&r=mysqlcfg