ReflectionMethod_getClosureThis.phpt 955 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. class Example
  19. {
  20. public $bar = 42;
  21. public function foo()
  22. {
  23. var_dump( "Example class, bar: " . $this->bar );
  24. }
  25. }
  26. // Initialize classes
  27. $class = new ReflectionClass( 'Example' );
  28. $staticclass = new ReflectionClass( 'StaticExample' );
  29. $object = new Example();
  30. $method = $staticclass->getMethod( 'foo' );
  31. $closure = $method->getClosure();
  32. $rf = new ReflectionFunction($closure);
  33. var_dump($rf->getClosureThis());
  34. $method = $class->getMethod( 'foo' );
  35. $closure = $method->getClosure( $object );
  36. $rf = new ReflectionFunction($closure);
  37. var_dump($rf->getClosureThis());
  38. echo "Done!\n";
  39. --EXPECTF--
  40. NULL
  41. object(Example)#%d (1) {
  42. ["bar"]=>
  43. int(42)
  44. }
  45. Done!