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 = ReflectionMethod::createFromMethodName('TestClass::staticMethod');
38$privateMethod = new ReflectionMethod("TestClass", "privateMethod");
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 "\nStatic method:\n";
48
49var_dump($staticMethod->invokeArgs(null, array()));
50
51echo "\nPrivate method:\n";
52var_dump($privateMethod->invokeArgs($testClassInstance, array()));
53
54echo "\nAbstract method:\n";
55$abstractMethod = new ReflectionMethod("AbstractClass", "foo");
56try {
57    $abstractMethod->invokeArgs($testClassInstance, array());
58} catch (ReflectionException $e) {
59    var_dump($e->getMessage());
60}
61try {
62    $abstractMethod->invokeArgs(true);
63} catch (ReflectionException $e) {
64    var_dump($e->getMessage());
65}
66
67?>
68--EXPECT--
69Non-instance:
70string(72) "Given object is not an instance of the class this method was declared in"
71
72Static method:
73Called staticMethod()
74Exception: Using $this when not in object context
75NULL
76
77Private method:
78Called privateMethod()
79NULL
80
81Abstract method:
82string(53) "Trying to invoke abstract method AbstractClass::foo()"
83string(53) "Trying to invoke abstract method AbstractClass::foo()"
84