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