Annotation of embedaddon/php/ext/reflection/tests/ReflectionMethod_invoke_basic.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: ReflectionMethod::invoke()
                      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:     public static function staticMethod() {
                     24:         echo "Called staticMethod()\n";
                     25:         var_dump($this);
                     26:     }
                     27: 
                     28:     private static function privateMethod() {
                     29:         echo "Called privateMethod()\n";
                     30:     }
                     31: }
                     32: 
                     33: abstract class AbstractClass {
                     34:     abstract function foo();
                     35: }
                     36: 
                     37: $foo = new ReflectionMethod('TestClass', 'foo');
                     38: $methodWithArgs = new ReflectionMethod('TestClass', 'methodWithArgs');
                     39: $staticMethod = new ReflectionMethod('TestClass::staticMethod');
                     40: $privateMethod = new ReflectionMethod("TestClass::privateMethod");
                     41: $methodThatThrows = new ReflectionMethod("TestClass::willThrow");
                     42: 
                     43: $testClassInstance = new TestClass();
                     44: $testClassInstance->prop = "Hello";
                     45: 
                     46: echo "Public method:\n";
                     47: 
                     48: var_dump($foo->invoke($testClassInstance));
                     49: 
                     50: var_dump($foo->invoke($testClassInstance, true));
                     51: 
                     52: echo "\nMethod with args:\n";
                     53: 
                     54: var_dump($methodWithArgs->invoke($testClassInstance, 1, "arg2"));
                     55: var_dump($methodWithArgs->invoke($testClassInstance, 1, "arg2", 3));
                     56: 
                     57: echo "\nStatic method:\n";
                     58: 
                     59: var_dump($staticMethod->invoke());
                     60: var_dump($staticMethod->invoke(true));
                     61: var_dump($staticMethod->invoke(new stdClass()));
                     62: 
                     63: echo "\nMethod that throws an exception:\n";
                     64: try {
                     65:        var_dump($methodThatThrows->invoke($testClassInstance));
                     66: } catch (Exception $exc) {
                     67:        var_dump($exc->getMessage());
                     68: }
                     69: 
                     70: ?>
                     71: --EXPECTF--
                     72: Public method:
                     73: Called foo(), property = Hello
                     74: object(TestClass)#%d (1) {
                     75:   ["prop"]=>
                     76:   string(5) "Hello"
                     77: }
                     78: string(10) "Return Val"
                     79: Called foo(), property = Hello
                     80: object(TestClass)#%d (1) {
                     81:   ["prop"]=>
                     82:   string(5) "Hello"
                     83: }
                     84: string(10) "Return Val"
                     85: 
                     86: Method with args:
                     87: Called methodWithArgs(1, arg2)
                     88: NULL
                     89: Called methodWithArgs(1, arg2)
                     90: NULL
                     91: 
                     92: Static method:
                     93: 
                     94: Warning: ReflectionMethod::invoke() expects at least 1 parameter, 0 given in %s on line %d
                     95: NULL
                     96: Called staticMethod()
                     97: 
                     98: Notice: Undefined variable: this in %s on line %d
                     99: NULL
                    100: NULL
                    101: Called staticMethod()
                    102: 
                    103: Notice: Undefined variable: this in %s on line %d
                    104: NULL
                    105: NULL
                    106: 
                    107: Method that throws an exception:
                    108: string(18) "Called willThrow()"

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>