Annotation of embedaddon/php/ext/reflection/tests/ReflectionMethod_invokeArgs_basic.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: ReflectionMethod::invokeArgs()
3: --FILE--
4: <?php
5:
6: class 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 function willThrow() {
16: throw new Exception("Called willThrow()");
17: }
18:
19: public function methodWithArgs($a, $b) {
20: echo "Called methodWithArgs($a, $b)\n";
21: }
22: }
23:
24:
25: $testClassInstance = new TestClass();
26: $testClassInstance->prop = "Hello";
27:
28: $foo = new ReflectionMethod($testClassInstance, 'foo');
29: $methodWithArgs = new ReflectionMethod('TestClass', 'methodWithArgs');
30: $methodThatThrows = new ReflectionMethod("TestClass::willThrow");
31:
32:
33: echo "Public method:\n";
34:
35: var_dump($foo->invokeArgs($testClassInstance, array()));
36: var_dump($foo->invokeArgs($testClassInstance, array(true)));
37:
38: echo "\nMethod with args:\n";
39:
40: var_dump($methodWithArgs->invokeArgs($testClassInstance, array(1, "arg2")));
41: var_dump($methodWithArgs->invokeArgs($testClassInstance, array(1, "arg2", 3)));
42:
43: echo "\nMethod that throws an exception:\n";
44: try {
45: $methodThatThrows->invokeArgs($testClassInstance, array());
46: } catch (Exception $e) {
47: var_dump($e->getMessage());
48: }
49:
50: ?>
51: --EXPECTF--
52: Public method:
53: Called foo(), property = Hello
54: object(TestClass)#%d (1) {
55: ["prop"]=>
56: string(5) "Hello"
57: }
58: string(10) "Return Val"
59: Called foo(), property = Hello
60: object(TestClass)#%d (1) {
61: ["prop"]=>
62: string(5) "Hello"
63: }
64: string(10) "Return Val"
65:
66: Method with args:
67: Called methodWithArgs(1, arg2)
68: NULL
69: Called methodWithArgs(1, arg2)
70: NULL
71:
72: Method that throws an exception:
73: string(18) "Called willThrow()"
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>