xref: /PHP-8.1/tests/classes/bug27504.phpt (revision 840e441d)
1--TEST--
2Bug #27504 (call_user_func_array allows calling of private/protected methods)
3--FILE--
4<?php
5class foo {
6    function __construct () {
7        $this->bar('1');
8    }
9    private function bar ( $param ) {
10        echo 'Called function foo:bar('.$param.')'."\n";
11    }
12}
13
14$foo = new foo();
15
16try {
17    call_user_func_array( array( $foo , 'bar' ) , array( '2' ) );
18} catch (TypeError $e) {
19    echo $e->getMessage(), "\n";
20}
21try {
22    $foo->bar('3');
23} catch (Error $e) {
24    echo $e->getMessage(), "\n";
25}
26
27?>
28--EXPECT--
29Called function foo:bar(1)
30call_user_func_array(): Argument #1 ($callback) must be a valid callback, cannot access private method foo::bar()
31Call to private method foo::bar() from global scope
32