bug66430.phpt 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. --TEST--
  2. Bug #66430: ReflectionFunction::invoke does not invoke closure with object scope
  3. --FILE--
  4. <?php
  5. class Alpha {
  6. public $message = "Valid representation";
  7. public function bravo() {
  8. return $this->message;
  9. }
  10. }
  11. $alpha = new Alpha();
  12. echo "alpha.bravo: ", $alpha->bravo().PHP_EOL;
  13. $reflection = new ReflectionObject($alpha);
  14. $method = $reflection->getMethod("bravo");
  15. $closure = $method->getClosure($alpha);
  16. $reflectionC = new ReflectionFunction($closure);
  17. echo "reflection of alpha.bravo: ", $method->invoke($alpha).PHP_EOL;
  18. echo "closure of alpha.bravo: ", $closure().PHP_EOL;
  19. echo "call_user_func of closure: ", call_user_func($closure).PHP_EOL;
  20. echo PHP_EOL;
  21. echo "closure cl of c(alpha.bravo): ", get_class($reflectionC->getClosureThis()).PHP_EOL;
  22. echo "scope cl of c(alpha.bravo): ", $reflectionC->getClosureScopeClass()->getName().PHP_EOL;
  23. echo "reflection of c(alpha.bravo): ", $reflectionC->invoke().PHP_EOL;
  24. ?>
  25. --EXPECT--
  26. alpha.bravo: Valid representation
  27. reflection of alpha.bravo: Valid representation
  28. closure of alpha.bravo: Valid representation
  29. call_user_func of closure: Valid representation
  30. closure cl of c(alpha.bravo): Alpha
  31. scope cl of c(alpha.bravo): Alpha
  32. reflection of c(alpha.bravo): Valid representation