<?php
declare(strict_types=1);
function setAge(int $age)
{
var_dump($age);
}
// First test is clearly wrong
// setAge("totally not an int"); <-- Fatal error expected int found string
// Try passing something like this
setAge("30+1");
// What about this?
setAge("30");
// Finally a real int :)
setAge(30);
// U jelly?
setAge(.1);
Fatal error: Uncaught TypeError: setAge(): Argument #1 ($age) must be of type int, string given, called in /in/b16nd on line 12 and defined in /in/b16nd:4
Stack trace:
#0 /in/b16nd(12): setAge('30+1')
#1 {main}
thrown in /in/b16nd on line 4
Process exited with code 255.
Output for 7.3.16 - 7.3.33, 7.4.0 - 7.4.33
Fatal error: Uncaught TypeError: Argument 1 passed to setAge() must be of the type int, string given, called in /in/b16nd on line 12 and defined in /in/b16nd:4
Stack trace:
#0 /in/b16nd(12): setAge('30+1')
#1 {main}
thrown in /in/b16nd on line 4
Process exited with code 255.
Fatal error: Uncaught TypeError: Argument 1 passed to setAge() must be of the type integer, string given, called in /in/b16nd on line 12 and defined in /in/b16nd:4
Stack trace:
#0 /in/b16nd(12): setAge('30+1')
#1 {main}
thrown in /in/b16nd on line 4
Process exited with code 255.
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28
Warning: Unsupported declare 'strict_types' in /in/b16nd on line 2
Catchable fatal error: Argument 1 passed to setAge() must be an instance of int, string given, called in /in/b16nd on line 12 and defined in /in/b16nd on line 4
Process exited with code 255.