ReflectionMethod_getClosure_basic.phpt 1022 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. --TEST--
  2. Test ReflectionMethod::getClosure() function : basic functionality
  3. --FILE--
  4. <?php
  5. echo "*** Testing ReflectionMethod::getClosure() : basic functionality ***\n";
  6. class StaticExample
  7. {
  8. static function foo()
  9. {
  10. var_dump( "Static Example class, Hello World!" );
  11. }
  12. }
  13. class Example
  14. {
  15. public $bar = 42;
  16. public function foo()
  17. {
  18. var_dump( "Example class, bar: " . $this->bar );
  19. }
  20. }
  21. // Initialize classes
  22. $class = new ReflectionClass( 'Example' );
  23. $staticclass = new ReflectionClass( 'StaticExample' );
  24. $object = new Example();
  25. $fakeobj = new StdClass();
  26. $method = $staticclass->getMethod( 'foo' );
  27. $closure = $method->getClosure();
  28. $closure();
  29. $method = $class->getMethod( 'foo' );
  30. $closure = $method->getClosure( $object );
  31. $closure();
  32. $object->bar = 34;
  33. $closure();
  34. ?>
  35. --EXPECT--
  36. *** Testing ReflectionMethod::getClosure() : basic functionality ***
  37. string(34) "Static Example class, Hello World!"
  38. string(22) "Example class, bar: 42"
  39. string(22) "Example class, bar: 34"