xref: /PHP-5.5/ext/spl/tests/spl_autoload_012.phpt (revision 610c7fbe)
1--TEST--
2SPL: spl_autoload() capturing multiple Exceptions in __autoload
3--FILE--
4<?php
5
6function autoload_first($name)
7{
8  echo __METHOD__ . "\n";
9  throw new Exception('first');
10}
11
12function autoload_second($name)
13{
14  echo __METHOD__ . "\n";
15  throw new Exception('second');
16}
17
18spl_autoload_register('autoload_first');
19spl_autoload_register('autoload_second');
20
21try {
22    class_exists('ThisClassDoesNotExist');
23} catch(Exception $e) {
24    do {
25        echo $e->getMessage()."\n";
26    } while($e = $e->getPrevious());
27}
28
29try {
30    new ThisClassDoesNotExist;
31} catch(Exception $e) {
32    do {
33        echo $e->getMessage()."\n";
34    } while($e = $e->getPrevious());
35}
36
37class_exists('ThisClassDoesNotExist');
38?>
39===DONE===
40--EXPECTF--
41autoload_first
42autoload_second
43second
44first
45autoload_first
46autoload_second
47second
48first
49autoload_first
50autoload_second
51
52Fatal error: Uncaught exception 'Exception' with message 'first' in %sspl_autoload_012.php:%d
53Stack trace:
54#0 [internal function]: autoload_first('ThisClassDoesNo...')
55#1 [internal function]: spl_autoload_call('ThisClassDoesNo...')
56#2 %sspl_autoload_012.php(%d): class_exists('ThisClassDoesNo...')
57#3 {main}
58
59Next exception 'Exception' with message 'second' in %sspl_autoload_012.php:%d
60Stack trace:
61#0 [internal function]: autoload_second('ThisClassDoesNo...')
62#1 [internal function]: spl_autoload_call('ThisClassDoesNo...')
63#2 %sspl_autoload_012.php(%d): class_exists('ThisClassDoesNo...')
64#3 {main}
65  thrown in %sspl_autoload_012.php on line %d
66