closure_059.phpt 779 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. --TEST--
  2. Closure 059: Closure type declaration
  3. --FILE--
  4. <?php
  5. class A {
  6. }
  7. class B {
  8. }
  9. $a = new A;
  10. $b = new B;
  11. $f = function (A $a){};
  12. $f($a);
  13. $f->__invoke($a);
  14. call_user_func(array($f,"__invoke"), $a);
  15. try {
  16. $f($b);
  17. } catch (Error $e) {
  18. echo "Exception: " . $e->getMessage() . "\n";
  19. }
  20. try {
  21. $f->__invoke($b);
  22. } catch (Error $e) {
  23. echo "Exception: " . $e->getMessage() . "\n";
  24. }
  25. try {
  26. call_user_func(array($f,"__invoke"), $b);
  27. } catch (Error $e) {
  28. echo "Exception: " . $e->getMessage() . "\n";
  29. }
  30. --EXPECTF--
  31. Exception: Argument 1 passed to {closure}() must be an instance of A, instance of B %s
  32. Exception: Argument 1 passed to {closure}() must be an instance of A, instance of B %s
  33. Exception: Argument 1 passed to {closure}() must be an instance of A, instance of B %s