1--TEST--
2ReflectionMethod::invokeArgs() further errors
3--FILE--
4<?php
5
6class TestClass {
7    public $prop = 2;
8
9    public function foo() {
10        echo "Called foo(), property = $this->prop\n";
11        var_dump($this);
12        return "Return Val";
13    }
14
15    public static function staticMethod() {
16        echo "Called staticMethod()\n";
17        var_dump($this);
18    }
19
20    private static function privateMethod() {
21        echo "Called privateMethod()\n";
22    }
23}
24
25abstract class AbstractClass {
26    abstract function foo();
27}
28
29$testClassInstance = new TestClass();
30$testClassInstance->prop = "Hello";
31
32$foo = new ReflectionMethod($testClassInstance, 'foo');
33$staticMethod = new ReflectionMethod('TestClass::staticMethod');
34$privateMethod = new ReflectionMethod("TestClass::privateMethod");
35
36echo "Wrong number of parameters:\n";
37var_dump($foo->invokeArgs());
38var_dump($foo->invokeArgs(true));
39
40echo "\nNon-instance:\n";
41try {
42    var_dump($foo->invokeArgs(new stdClass(), array()));
43} catch (ReflectionException $e) {
44    var_dump($e->getMessage());
45}
46
47echo "\nNon-object:\n";
48var_dump($foo->invokeArgs(true, array()));
49
50echo "\nStatic method:\n";
51
52var_dump($staticMethod->invokeArgs());
53var_dump($staticMethod->invokeArgs(true));
54var_dump($staticMethod->invokeArgs(true, array()));
55var_dump($staticMethod->invokeArgs(null, array()));
56
57echo "\nPrivate method:\n";
58try {
59    var_dump($privateMethod->invokeArgs($testClassInstance, array()));
60} catch (ReflectionException $e) {
61    var_dump($e->getMessage());
62}
63
64echo "\nAbstract method:\n";
65$abstractMethod = new ReflectionMethod("AbstractClass::foo");
66try {
67    $abstractMethod->invokeArgs($testClassInstance, array());
68} catch (ReflectionException $e) {
69    var_dump($e->getMessage());
70}
71try {
72    $abstractMethod->invokeArgs(true);
73} catch (ReflectionException $e) {
74    var_dump($e->getMessage());
75}
76
77?>
78--EXPECTF--
79Wrong number of parameters:
80
81Warning: ReflectionMethod::invokeArgs() expects exactly 2 parameters, 0 given in %s on line %d
82NULL
83
84Warning: ReflectionMethod::invokeArgs() expects exactly 2 parameters, 1 given in %s on line %d
85NULL
86
87Non-instance:
88string(72) "Given object is not an instance of the class this method was declared in"
89
90Non-object:
91
92Warning: ReflectionMethod::invokeArgs() expects parameter 1 to be object, boolean given in %s on line %d
93NULL
94
95Static method:
96
97Warning: ReflectionMethod::invokeArgs() expects exactly 2 parameters, 0 given in %s on line %d
98NULL
99
100Warning: ReflectionMethod::invokeArgs() expects exactly 2 parameters, 1 given in %s on line %d
101NULL
102
103Warning: ReflectionMethod::invokeArgs() expects parameter 1 to be object, boolean given in %s on line %d
104NULL
105Called staticMethod()
106
107Notice: Undefined variable: this in %s on line %d
108NULL
109NULL
110
111Private method:
112string(86) "Trying to invoke private method TestClass::privateMethod() from scope ReflectionMethod"
113
114Abstract method:
115string(53) "Trying to invoke abstract method AbstractClass::foo()"
116
117Warning: ReflectionMethod::invokeArgs() expects exactly 2 parameters, 1 given in %s on line %d
118