|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-07-12 19:43 UTC] ryan dot brothers at gmail dot com
Description: ------------ This issue may be the same issue as bug 65254 that I just submitted. The following script throws a Fatal Error rather than catching the exception. Test script: --------------- <?php function __autoload($class) { throw new Exception('abcd'); } class test1 extends test2 { public static function go() { } } try { test1::go(); } catch (Exception $e) { echo 'caught'; exit; } Expected result: ---------------- caught Actual result: -------------- Fatal error: Uncaught exception 'Exception' with message 'abcd' in /tmp/test.php:4 Stack trace: #0 /tmp/test.php(8): __autoload('test2') #1 {main} thrown in /tmp/test.php on line 4 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 07:00:01 2025 UTC |
Thank you for your help. Why does it matter if the class was declared literally in the try/catch block? The documentation states "exceptions thrown in the __autoload function can be caught in the catch block". It works for the base class, but not extended classes. Other exceptions thrown outside of a try/catch always propagate back to the caller's try/catch such as the below. In these examples, the exception is caught, but the exception is thrown outside of the literal try/catch. <?php function __autoload($class) { throw new Exception('abcd'); } try { test1::go(); } catch (Exception $e) { echo 'caught'; exit; } ================================================= <?php function test() { throw new Exception('abcd'); } try { test(); } catch (Exception $e) { echo 'caught'; exit; } ================================================= <?php class test1 { public static function go() { throw new Exception('abcd'); } } try { test1::go(); } catch (Exception $e) { echo 'caught'; exit; }