xref: /PHP-7.1/Zend/tests/closure_027.phpt (revision ff363e2e)
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
30Notice: 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: Argument 1 passed to test() must be an instance of Closure, instance of stdClass given, called in %s on line %d and defined in %s:%d
34Stack trace:
35#0 %s(%d): test(Object(stdClass))
36#1 {main}
37  thrown in %s on line %d
38