xref: /PHP-8.0/Zend/tests/bug32290.phpt (revision f8d79582)
1--TEST--
2Bug #32290 (calling call_user_func_array() ends in infinite loop within child class)
3--INI--
4error_reporting=8191
5--FILE--
6<?php
7
8class TestA
9{
10    public function doSomething($i)
11    {
12        echo __METHOD__ . "($i)\n";
13        return --$i;
14    }
15
16    public function doSomethingThis($i)
17    {
18        echo __METHOD__ . "($i)\n";
19        return --$i;
20    }
21
22    public function doSomethingParent($i)
23    {
24        echo __METHOD__ . "($i)\n";
25        return --$i;
26    }
27
28    public function doSomethingParentThis($i)
29    {
30        echo __METHOD__ . "($i)\n";
31        return --$i;
32    }
33
34    public static function doSomethingStatic($i)
35    {
36        echo __METHOD__ . "($i)\n";
37        return --$i;
38    }
39}
40
41class TestB extends TestA
42{
43    public function doSomething($i)
44    {
45        echo __METHOD__ . "($i)\n";
46        $i++;
47        if ($i >= 5) return 5;
48        return call_user_func_array(array("TestA", "doSomething"), array($i));
49    }
50
51    public function doSomethingThis($i)
52    {
53        echo __METHOD__ . "($i)\n";
54        $i++;
55        if ($i >= 5) return 5;
56        return call_user_func_array(array($this, "TestA::doSomethingThis"), array($i));
57    }
58
59    public function doSomethingParent($i)
60    {
61        echo __METHOD__ . "($i)\n";
62        $i++;
63        if ($i >= 5) return 5;
64        return call_user_func_array(array("parent", "doSomethingParent"), array($i));
65    }
66
67    public function doSomethingParentThis($i)
68    {
69        echo __METHOD__ . "($i)\n";
70        $i++;
71        if ($i >= 5) return 5;
72        return call_user_func_array(array($this, "parent::doSomethingParentThis"), array($i));
73    }
74
75    public static function doSomethingStatic($i)
76    {
77        echo __METHOD__ . "($i)\n";
78        $i++;
79        if ($i >= 5) return 5;
80        return call_user_func_array(array("TestA", "doSomethingStatic"), array($i));
81    }
82}
83
84$x = new TestB();
85echo "===A===\n";
86var_dump($x->doSomething(1));
87echo "\n===B===\n";
88var_dump($x->doSomethingThis(1));
89echo "\n===C===\n";
90var_dump($x->doSomethingParent(1));
91echo "\n===D===\n";
92var_dump($x->doSomethingParentThis(1));
93echo "\n===E===\n";
94var_dump($x->doSomethingStatic(1));
95
96?>
97--EXPECT--
98===A===
99TestB::doSomething(1)
100TestA::doSomething(2)
101int(1)
102
103===B===
104TestB::doSomethingThis(1)
105TestA::doSomethingThis(2)
106int(1)
107
108===C===
109TestB::doSomethingParent(1)
110TestA::doSomethingParent(2)
111int(1)
112
113===D===
114TestB::doSomethingParentThis(1)
115TestA::doSomethingParentThis(2)
116int(1)
117
118===E===
119TestB::doSomethingStatic(1)
120TestA::doSomethingStatic(2)
121int(1)
122