xref: /PHP-8.2/Zend/tests/bug31102.phpt (revision d30cd7d7)
1--TEST--
2Bug #31102 (Exception not handled when thrown inside autoloader)
3--FILE--
4<?php
5
6$test = 0;
7
8spl_autoload_register(function ($class) {
9    global $test;
10
11    echo __METHOD__ . "($class,$test)\n";
12    switch($test)
13    {
14    case 1:
15        eval("class $class { function __construct(){throw new Exception('$class::__construct');}}");
16        return;
17    case 2:
18        eval("class $class { function __construct(){throw new Exception('$class::__construct');}}");
19        throw new Exception(__METHOD__);
20        return;
21    case 3:
22        return;
23    }
24});
25
26while($test++ < 5)
27{
28    try
29    {
30        eval("\$bug = new Test$test();");
31    }
32    catch (Exception $e)
33    {
34        echo "Caught: " . $e->getMessage() . "\n";
35    }
36}
37?>
38===DONE===
39--EXPECTF--
40{closure}(Test1,1)
41Caught: Test1::__construct
42{closure}(Test2,2)
43Caught: {closure}
44{closure}(Test3,3)
45
46Fatal error: Uncaught Error: Class "Test3" not found in %s:%d
47Stack trace:
48#0 %s(%d): eval()
49#1 {main}
50  thrown in %sbug31102.php(%d) : eval()'d code on line 1
51