Bug #70844 [Opn->Csd]: spl_autoload_register throws expected exception too early
| From: | nikic@php.net | Date: | Fri, 18 Mar 2016 19:46:44 +0000 |
| Subject: | Bug #70844 [Opn->Csd]: spl_autoload_register throws expected exception too early | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-199932@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
Updated by: nikic@php.net
Reported by: mjauram at gmail dot com
Summary: spl_autoload_register throws expected exception too
early
-Status: Open
+Status: Closed
Type: Bug
Package: SPL related
Operating System: Windows/Linux
PHP Version: 5.5.30
-Assigned To:
+Assigned To: nikic
Block user comment: N
Private report: N
Previous Comments:
------------------------------------------------------------------------
[2016-03-18 19:46:34] nikic@php.net
Closing here, as both examples seem to be working fine now: https://3v4l.org/TAkta and https://3v4l.org/Bn1d8. On 5.6 you get the fatal error from class
loading, on 7.0 chained exceptions.
------------------------------------------------------------------------
[2015-12-14 13:26:20] andreimarchenko90 at gmail dot com
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.
------------------------------------------------------------------------
[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