xref: /PHP-8.3/Zend/tests/bug48770_2.phpt (revision ee510eed)
1--TEST--
2Bug #48770 (call_user_func_array() fails to call parent from inheriting class)
3--FILE--
4<?php
5
6class A {
7    public function func($str) {
8        var_dump(__METHOD__ .': '. $str);
9    }
10    private function func2($str) {
11        var_dump(__METHOD__ .': '. $str);
12    }
13    protected function func3($str) {
14        var_dump(__METHOD__ .': '. $str);
15    }
16    private function func22($str) {
17        var_dump(__METHOD__ .': '. $str);
18    }
19}
20
21class B extends A {
22    public function func($str) {
23        call_user_func_array(array($this, 'parent::func2'), array($str));
24        call_user_func_array(array($this, 'parent::func3'), array($str));
25
26        try {
27            call_user_func_array(array($this, 'parent::func22'), array($str));
28        } catch (\TypeError $e) {
29            echo $e->getMessage() . \PHP_EOL;
30        }
31
32        try {
33            call_user_func_array(array($this, 'parent::inexistent'), array($str));
34        } catch (\TypeError $e) {
35            echo $e->getMessage() . \PHP_EOL;
36        }
37    }
38    private function func2($str) {
39        var_dump(__METHOD__ .': '. $str);
40    }
41    protected function func3($str) {
42        var_dump(__METHOD__ .': '. $str);
43    }
44}
45
46class C extends B {
47    public function func($str) {
48        parent::func($str);
49    }
50}
51
52$c = new C;
53$c->func('This should work!');
54
55?>
56--EXPECTF--
57Deprecated: Callables of the form ["C", "parent::func2"] are deprecated in %s on line %d
58string(27) "B::func2: This should work!"
59
60Deprecated: Callables of the form ["C", "parent::func3"] are deprecated in %s on line %d
61string(27) "B::func3: This should work!"
62
63Deprecated: Callables of the form ["C", "parent::func22"] are deprecated in %s on line %d
64call_user_func_array(): Argument #1 ($callback) must be a valid callback, cannot access private method B::func22()
65
66Deprecated: Callables of the form ["C", "parent::inexistent"] are deprecated in %s on line %d
67call_user_func_array(): Argument #1 ($callback) must be a valid callback, class B does not have a method "inexistent"
68