Mchl Posted October 30, 2009 Share Posted October 30, 2009 Manual says: Note: Exceptions thrown in __autoload function cannot be caught in the catch block and results in a fatal error. However when I run this code: <?php function __autoload($className) { if(file_exists("/classes/$className.class.php")) { require_once("/classes/$className.class.php"); } else { throw new Exception("File /classes/$className.class.php does not exist"); } } try { $foo = new foo(); } catch(Exception $e) { echo 'Exception caught:'.PHP_EOL; echo $e->getMessage(); } no fatal error occurs. Exception is handled as usual. I am doing this in 5.3 right now, but IIRC this was also a case in 5.2 Link to comment https://forums.phpfreaks.com/topic/179679-throwing-exception-in-__autoload/ Share on other sites More sharing options...
salathe Posted October 30, 2009 Share Posted October 30, 2009 I think (my memory isn't what it used to be) this might have been "fixed" for 5.3.0... I'll take a look-see for more info. P.S. Yep looks like 5.2 still suffers (just tried 5.2.11) and 5.3 (tested on 5.3.0) works as your post says. If that's the case, the note on the manual page will get amended. Link to comment https://forums.phpfreaks.com/topic/179679-throwing-exception-in-__autoload/#findComment-948071 Share on other sites More sharing options...
Mchl Posted October 30, 2009 Author Share Posted October 30, 2009 Thanks for that info. I vaguely remember 5.2.x also behaving in this way... but then my memory also isn't what it used to be. And I used to have quite a mess in php installations at one time. Link to comment https://forums.phpfreaks.com/topic/179679-throwing-exception-in-__autoload/#findComment-948075 Share on other sites More sharing options...
Mchl Posted October 30, 2009 Author Share Posted October 30, 2009 From PHP 5.3 changelog: [*] Added delaying exceptions in SPL's autoload mechanism. (Marcus) Also related: [*] Fixed bug #47714 (autoloading classes inside exception_handler leads to crashes). (Dmitry) Link to comment https://forums.phpfreaks.com/topic/179679-throwing-exception-in-__autoload/#findComment-948079 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.