ReflectionMethod_getClosureThis.phpt 857 B

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