xref: /PHP-8.3/ext/spl/tests/gh10011.phpt (revision 608ddb03)
1--TEST--
2Bug GH-10011 (Trampoline autoloader will get reregistered and cannot be unregistered)
3--FILE--
4<?php
5
6class TrampolineTest {
7    public function __call(string $name, array $arguments) {
8        echo 'Trampoline for ', $name, PHP_EOL;
9    }
10}
11$o = new TrampolineTest();
12$callback1 = [$o, 'trampoline1'];
13$callback2 = [$o, 'trampoline2'];
14
15spl_autoload_register($callback1);
16spl_autoload_register($callback2);
17spl_autoload_register($callback1); // 2nd call ignored
18
19var_dump(spl_autoload_functions());
20
21var_dump(class_exists("TestClass", true));
22
23echo "Unregister trampoline:\n";
24var_dump(spl_autoload_unregister($callback1));
25var_dump(spl_autoload_unregister($callback1));
26var_dump(spl_autoload_unregister($callback2));
27
28var_dump(spl_autoload_functions());
29var_dump(class_exists("TestClass", true));
30?>
31--EXPECT--
32array(2) {
33  [0]=>
34  array(2) {
35    [0]=>
36    object(TrampolineTest)#1 (0) {
37    }
38    [1]=>
39    string(11) "trampoline1"
40  }
41  [1]=>
42  array(2) {
43    [0]=>
44    object(TrampolineTest)#1 (0) {
45    }
46    [1]=>
47    string(11) "trampoline2"
48  }
49}
50Trampoline for trampoline1
51Trampoline for trampoline2
52bool(false)
53Unregister trampoline:
54bool(true)
55bool(false)
56bool(true)
57array(0) {
58}
59bool(false)
60