closure_027.phpt 732 B

12345678910111213141516171819202122232425262728293031323334353637
  1. --TEST--
  2. Closure 027: Testing Closure type-hint
  3. --FILE--
  4. <?php
  5. function test(Closure $a) {
  6. var_dump($a());
  7. }
  8. test(function() { return new stdclass; });
  9. test(function() { });
  10. $a = function($x) use ($y) {};
  11. try {
  12. test($a);
  13. } catch (Throwable $e) {
  14. echo "Exception: " . $e->getMessage() . "\n";
  15. }
  16. test(new stdclass);
  17. ?>
  18. --EXPECTF--
  19. object(stdClass)#%d (0) {
  20. }
  21. NULL
  22. Warning: Undefined variable $y in %s on line %d
  23. Exception: Too few arguments to function {closure}(), 0 passed in %s on line %d and exactly 1 expected
  24. Fatal error: Uncaught TypeError: test(): Argument #1 ($a) must be of type Closure, stdClass given, called in %s:%d
  25. Stack trace:
  26. #0 %s(%d): test(Object(stdClass))
  27. #1 {main}
  28. thrown in %s on line %d