xref: /PHP-7.0/Zend/tests/bug68475.phpt (revision 64b167d2)
1--TEST--
2Bug #68475 Calling function using $callable() syntax with strings of form 'Class::method'
3--FILE--
4<?php
5class TestClass
6{
7    public static function staticMethod()
8    {
9        echo "Static method called!\n";
10    }
11
12    public static function staticMethodWithArgs($arg1, $arg2, $arg3)
13    {
14        printf("Static method called with args: %s, %s, %s\n", $arg1, $arg2, $arg3);
15    }
16}
17
18// Test basic call using Class::method syntax.
19$callback = 'TestClass::staticMethod';
20$callback();
21
22// Case should not matter.
23$callback = 'testclass::staticmethod';
24$callback();
25
26$args = ['arg1', 'arg2', 'arg3'];
27$callback = 'TestClass::staticMethodWithArgs';
28
29// Test call with args.
30$callback($args[0], $args[1], $args[2]);
31
32// Test call with splat operator.
33$callback(...$args);
34
35// Reference undefined method.
36$callback = 'TestClass::undefinedMethod';
37try {
38    $callback();
39} catch (Error $e) {
40    echo $e->getMessage() . "\n";
41}
42
43// Reference undefined class.
44$callback = 'UndefinedClass::testMethod';
45try {
46    $callback();
47} catch (Error $e) {
48    echo $e->getMessage() . "\n";
49}
50?>
51--EXPECT--
52Static method called!
53Static method called!
54Static method called with args: arg1, arg2, arg3
55Static method called with args: arg1, arg2, arg3
56Call to undefined method TestClass::undefinedMethod()
57Class 'UndefinedClass' not found
58