Bug #70844 [Com]: spl_autoload_register throws expected exception too early

From: Date: Mon, 14 Dec 2015 13:26:22 +0000
Subject: Bug #70844 [Com]: spl_autoload_register throws expected exception too early
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-197861@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70844&edit=1 ID: 70844 Comment by: andreimarchenko90 at gmail dot com Reported by: mjauram at gmail dot com Summary: spl_autoload_register throws expected exception too early Status: Open Type: Bug Package: SPL related Operating System: Windows/Linux PHP Version: 5.5.30 Block user comment: N Private report: N New Comment: The same situation with this bug: <?php spl_autoload_register(function ($class_name) { echo "Need to include {$class_name} \n"; }); try { try { throw new \RuntimeException('Error message'); } finally { echo 'Start finally block' . PHP_EOL; $foo = new Foo(); echo 'End finally block' . PHP_EOL; } } catch (\Exception $e) { echo $e->getMessage() . PHP_EOL; echo $e . PHP_EOL; } Actual result: Start finally block Need to include Foo Error message exception 'RuntimeException' with message 'Error message' in /in/Bn1d8:8 Stack trace: #0 {main} Expected result: Start finally block Need to include Foo Fatal error: Uncaught RuntimeException: Error message in /in/Bn1d8:8 Stack trace: #0 {main} Next Error: Class 'Foo' not found in /in/Bn1d8:11 Stack trace: #0 {main} thrown in /in/Bn1d8 on line 11 Process exited with code 255. Previous Comments: ------------------------------------------------------------------------ [2015-11-03 14:47:08] mjauram at gmail dot com Description: ------------ If loading classes dynamically inside of the finally block's try-catch block then auto load throws previously throwed exception which is catched. Test script: --------------- Full example here: https://goo.gl/08KRD2 try { throw new \Exception('Exception'); } catch (\Exception $e) { throw new \Exception('New Exception'); } finally { try{ myclass2::test(); // spl_autoload_register function to load classes } catch (\Exception $ex) { var_dump('this is not expected:', $ex); // this is not expected but "New Exception" is caught here } } Expected result: ---------------- New Exception is thrown not catched. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=70844&edit=1

« previous php.bugs (#197861) next »