1--TEST--
2ReflectionMethod::invoke() 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    private static function privateMethod() {
16        echo "Called privateMethod()\n";
17    }
18}
19
20abstract class AbstractClass {
21    abstract function foo();
22}
23
24$foo = new ReflectionMethod('TestClass', 'foo');
25$privateMethod = new ReflectionMethod("TestClass::privateMethod");
26
27$testClassInstance = new TestClass();
28$testClassInstance->prop = "Hello";
29
30echo "invoke() on a non-object:\n";
31try {
32    var_dump($foo->invoke(true));
33} catch (TypeError $e) {
34    var_dump($e->getMessage());
35}
36
37echo "\ninvoke() on a non-instance:\n";
38try {
39    var_dump($foo->invoke(new stdClass()));
40} catch (ReflectionException $e) {
41    var_dump($e->getMessage());
42}
43
44echo "\nPrivate method:\n";
45var_dump($privateMethod->invoke($testClassInstance));
46
47echo "\nAbstract method:\n";
48$abstractMethod = new ReflectionMethod("AbstractClass::foo");
49try {
50    $abstractMethod->invoke(true);
51} catch (ReflectionException $e) {
52    var_dump($e->getMessage());
53}
54
55?>
56--EXPECT--
57invoke() on a non-object:
58string(85) "ReflectionMethod::invoke(): Argument #1 ($object) must be of type ?object, bool given"
59
60invoke() on a non-instance:
61string(72) "Given object is not an instance of the class this method was declared in"
62
63Private method:
64Called privateMethod()
65NULL
66
67Abstract method:
68string(53) "Trying to invoke abstract method AbstractClass::foo()"
69