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

1.1       misho       1: --TEST--
                      2: Reflection::getClosureThis()
                      3: --SKIPIF--
                      4: <?php
                      5: if (!extension_loaded('reflection') || !defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50300) {
                      6:   print 'skip';
                      7: }
                      8: ?>
                      9: --FILE-- 
                     10: <?php
                     11: class StaticExample
                     12: {
                     13:        static function foo()
                     14:        {
                     15:                var_dump( "Static Example class, Hello World!" );
                     16:        }
                     17: }
                     18: 
                     19: class Example
                     20: {
                     21:        public $bar = 42;
                     22:        public function foo()
                     23:        {
                     24:                var_dump( "Example class, bar: " . $this->bar );
                     25:        }
                     26: }
                     27: 
                     28: // Initialize classes
                     29: $class = new ReflectionClass( 'Example' );
                     30: $staticclass = new ReflectionClass( 'StaticExample' );
                     31: $object = new Example();
                     32: 
                     33: $method = $staticclass->getMethod( 'foo' );
                     34: $closure = $method->getClosure();
                     35: $rf = new ReflectionFunction($closure);
                     36: 
                     37: var_dump($rf->getClosureThis());
                     38: 
                     39: $method = $class->getMethod( 'foo' );
                     40: 
                     41: $closure = $method->getClosure( $object );
                     42: $rf = new ReflectionFunction($closure);
                     43: 
                     44: var_dump($rf->getClosureThis());
                     45: 
                     46: echo "Done!\n";
                     47: --EXPECTF--
                     48: NULL
                     49: object(Example)#%d (1) {
                     50:   ["bar"]=>
                     51:   int(42)
                     52: }
                     53: Done!

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