xref: /PHP-7.3/Zend/tests/bug31102.phpt (revision 162aa1a5)
1--TEST--
2Bug #31102 (Exception not handled when thrown inside __autoload())
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<?php exit(0); ?>
40--EXPECTF--
41{closure}(Test1,1)
42Caught: Test1::__construct
43{closure}(Test2,2)
44Caught: {closure}
45{closure}(Test3,3)
46
47Fatal error: Uncaught Error: Class 'Test3' not found in %sbug31102.php(%d) : eval()'d code:1
48Stack trace:
49#0 %s(%d): eval()
50#1 {main}
51  thrown in %sbug31102.php(%d) : eval()'d code on line 1
52