1--TEST--
2Scalar type nullability
3--FILE--
4<?php
5
6$functions = [
7    'int' => function (int $i) { return $i; },
8    'float' => function (float $f) { return $f; },
9    'string' => function (string $s) { return $s; },
10    'bool' => function (bool $b) { return $b; },
11    'int nullable' => function (int $i = NULL) { return $i; },
12    'float nullable' => function (float $f = NULL) { return $f; },
13    'string nullable' => function (string $s = NULL) { return $s; },
14    'bool nullable' => function (bool $b = NULL) { return $b; }
15];
16
17foreach ($functions as $type => $function) {
18    echo "Testing $type:", PHP_EOL;
19    try {
20        var_dump($function(null));
21    } catch (TypeError $e) {
22        echo "*** Caught " . $e->getMessage() . PHP_EOL;
23    }
24}
25
26echo PHP_EOL . "Done";
27?>
28--EXPECTF--
29Testing int:
30*** Caught Argument 1 passed to {closure}() must be of the type int, null given, called in %s on line %d
31Testing float:
32*** Caught Argument 1 passed to {closure}() must be of the type float, null given, called in %s on line %d
33Testing string:
34*** Caught Argument 1 passed to {closure}() must be of the type string, null given, called in %s on line %d
35Testing bool:
36*** Caught Argument 1 passed to {closure}() must be of the type bool, null given, called in %s on line %d
37Testing int nullable:
38NULL
39Testing float nullable:
40NULL
41Testing string nullable:
42NULL
43Testing bool nullable:
44NULL
45
46Done
47