xref: /PHP-8.1/Zend/tests/bug48770_3.phpt (revision 840e441d)
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}
17
18class B extends A {
19    public function func($str) {
20        call_user_func_array(array($this, 'self::func2'), array($str));
21        call_user_func_array(array($this, 'self::func3'), array($str));
22
23        try {
24            call_user_func_array(array($this, 'self::inexistent'), array($str));
25        } catch (\TypeError $e) {
26            echo $e->getMessage() . \PHP_EOL;
27        }
28    }
29    private function func2($str) {
30        var_dump(__METHOD__ .': '. $str);
31    }
32    protected function func3($str) {
33        var_dump(__METHOD__ .': '. $str);
34    }
35}
36
37class C extends B {
38    public function func($str) {
39        parent::func($str);
40    }
41}
42
43$c = new C;
44$c->func('This should work!');
45
46?>
47--EXPECT--
48string(27) "B::func2: This should work!"
49string(27) "B::func3: This should work!"
50call_user_func_array(): Argument #1 ($callback) must be a valid callback, class C does not have a method "inexistent"
51