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";
19 } catch (Throwable $e) {
20 echo "Exception: " . $e->getMessage() . "\n";
24 private static function privateMethod() {
25 echo "Called privateMethod()\n";
29 abstract class AbstractClass {
30 abstract function foo();
33 $testClassInstance = new TestClass();
34 $testClassInstance->prop = "Hello";
36 $foo = new ReflectionMethod($testClassInstance, 'foo');
37 $staticMethod = new ReflectionMethod('TestClass::staticMethod');
38 $privateMethod = new ReflectionMethod("TestClass::privateMethod");
40 echo "\nNon-instance:\n";
42 var_dump($foo->invokeArgs(new stdClass(), array()));
43 } catch (ReflectionException $e) {
44 var_dump($e->getMessage());
47 echo "\nStatic method:\n";
49 var_dump($staticMethod->invokeArgs(null, array()));
51 echo "\nPrivate method:\n";
53 var_dump($privateMethod->invokeArgs($testClassInstance, array()));
54 } catch (ReflectionException $e) {
55 var_dump($e->getMessage());
58 echo "\nAbstract method:\n";
59 $abstractMethod = new ReflectionMethod("AbstractClass::foo");
61 $abstractMethod->invokeArgs($testClassInstance, array());
62 } catch (ReflectionException $e) {
63 var_dump($e->getMessage());
66 $abstractMethod->invokeArgs(true);
67 } catch (ReflectionException $e) {
68 var_dump($e->getMessage());
74 string(72) "Given object is not an instance of the class this method was declared in"
78 Exception: Using $this when not in object context
82 string(86) "Trying to invoke private method TestClass::privateMethod() from scope ReflectionMethod"
85 string(53) "Trying to invoke abstract method AbstractClass::foo()"
86 string(53) "Trying to invoke abstract method AbstractClass::foo()"