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