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