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