closure_from_callable_reflection.phpt 743 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. --TEST--
  2. Testing Closure::fromCallable() functionality: Reflection
  3. --FILE--
  4. <?php
  5. class Bar {
  6. public static function staticMethod(Bar $bar, int $int, $none) {}
  7. public static function instanceMethod(Bar $bar, int $int, $none) {}
  8. }
  9. function foo(Bar $bar, int $int, $none) {
  10. }
  11. $fn = function (Bar $bar, int $x, $none) {};
  12. $bar = new Bar();
  13. $callables = [
  14. 'foo',
  15. $fn,
  16. 'Bar::staticMethod',
  17. [$bar, 'instanceMethod']
  18. ];
  19. foreach ($callables as $callable) {
  20. $closure = Closure::fromCallable($callable);
  21. $refl = new ReflectionFunction($closure);
  22. foreach ($refl->getParameters() as $param) {
  23. if ($param->hasType()) {
  24. $type = $param->getType();
  25. echo $type->getName() . "\n";
  26. }
  27. }
  28. }
  29. ?>
  30. --EXPECT--
  31. Bar
  32. int
  33. Bar
  34. int
  35. Bar
  36. int
  37. Bar
  38. int