2
ReflectionMethod::invokeArgs() further errors
9
public function foo() {
10
echo "Called foo(), property = $this->prop\n";
15
public static function staticMethod() {
16
echo "Called staticMethod()\n";
20
private static function privateMethod() {
21
echo "Called privateMethod()\n";
25
abstract class AbstractClass {
26
abstract function foo();
29
$testClassInstance = new TestClass();
30
$testClassInstance->prop = "Hello";
32
$foo = new ReflectionMethod($testClassInstance, 'foo');
33
$staticMethod = new ReflectionMethod('TestClass::staticMethod');
34
$privateMethod = new ReflectionMethod("TestClass::privateMethod");
36
echo "Wrong number of parameters:\n";
37
var_dump($foo->invokeArgs());
38
var_dump($foo->invokeArgs(true));
40
echo "\nNon-instance:\n";
42
var_dump($foo->invokeArgs(new stdClass(), array()));
43
} catch (ReflectionException $e) {
44
var_dump($e->getMessage());
47
echo "\nNon-object:\n";
48
var_dump($foo->invokeArgs(true, array()));
50
echo "\nStatic method:\n";
52
var_dump($staticMethod->invokeArgs());
53
var_dump($staticMethod->invokeArgs(true));
54
var_dump($staticMethod->invokeArgs(true, array()));
55
var_dump($staticMethod->invokeArgs(null, array()));
57
echo "\nPrivate method:\n";
59
var_dump($privateMethod->invokeArgs($testClassInstance, array()));
60
} catch (ReflectionException $e) {
61
var_dump($e->getMessage());
64
echo "\nAbstract method:\n";
65
$abstractMethod = new ReflectionMethod("AbstractClass::foo");
67
$abstractMethod->invokeArgs($testClassInstance, array());
68
} catch (ReflectionException $e) {
69
var_dump($e->getMessage());
72
$abstractMethod->invokeArgs(true);
73
} catch (ReflectionException $e) {
74
var_dump($e->getMessage());
79
Wrong number of parameters:
81
Warning: ReflectionMethod::invokeArgs() expects exactly 2 parameters, 0 given in %s on line %d
84
Warning: ReflectionMethod::invokeArgs() expects exactly 2 parameters, 1 given in %s on line %d
88
string(72) "Given object is not an instance of the class this method was declared in"
92
Warning: ReflectionMethod::invokeArgs() expects parameter 1 to be object, boolean given in %s on line %d
97
Warning: ReflectionMethod::invokeArgs() expects exactly 2 parameters, 0 given in %s on line %d
100
Warning: ReflectionMethod::invokeArgs() expects exactly 2 parameters, 1 given in %s on line %d
103
Warning: ReflectionMethod::invokeArgs() expects parameter 1 to be object, boolean given in %s on line %d
105
Called staticMethod()
107
Notice: Undefined variable: this in %s on line %d
112
string(84) "Trying to invoke private method TestClass::privateMethod from scope ReflectionMethod"
115
string(51) "Trying to invoke abstract method AbstractClass::foo"
117
Warning: ReflectionMethod::invokeArgs() expects exactly 2 parameters, 1 given in %s on line %d