<?php
function foo(int $bar) { var_dump($bar); }
echo "These ones are all ok:".PHP_EOL;
foo(7);
foo('7');
foo("7345");
echo PHP_EOL."And now for a bad one...".PHP_EOL;
foo("sgjhdfkg");
These ones are all ok:
int(7)
int(7)
int(7345)
And now for a bad one...
Fatal error: Uncaught TypeError: foo(): Argument #1 ($bar) must be of type int, string given, called in /in/LnQvW on line 11 and defined in /in/LnQvW:3
Stack trace:
#0 /in/LnQvW(11): foo('sgjhdfkg')
#1 {main}
thrown in /in/LnQvW on line 3
Process exited with code 255.
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
These ones are all ok:
int(7)
int(7)
int(7345)
And now for a bad one...
Fatal error: Uncaught TypeError: Argument 1 passed to foo() must be of the type int, string given, called in /in/LnQvW on line 11 and defined in /in/LnQvW:3
Stack trace:
#0 /in/LnQvW(11): foo('sgjhdfkg')
#1 {main}
thrown in /in/LnQvW on line 3
Process exited with code 255.
These ones are all ok:
int(7)
int(7)
int(7345)
And now for a bad one...
Fatal error: Uncaught TypeError: Argument 1 passed to foo() must be of the type integer, string given, called in /in/LnQvW on line 11 and defined in /in/LnQvW:3
Stack trace:
#0 /in/LnQvW(11): foo('sgjhdfkg')
#1 {main}
thrown in /in/LnQvW on line 3
Process exited with code 255.
These ones are all ok:
Catchable fatal error: Argument 1 passed to foo() must be an instance of int, integer given, called in /in/LnQvW on line 6 and defined in /in/LnQvW on line 3
Process exited with code 255.
Output for 5.1.0 - 5.1.6
These ones are all ok:
Fatal error: Argument 1 passed to foo() must be an object of class int, called in /in/LnQvW on line 6 and defined in /in/LnQvW on line 3
Process exited with code 255.
Output for 5.0.2 - 5.0.5
These ones are all ok:
Fatal error: Argument 1 must be an object of class int in /in/LnQvW on line 3
Process exited with code 255.
Output for 5.0.0 - 5.0.1
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LnQvW on line 5
These ones are all ok:PHP_EOL
Fatal error: Argument 1 must be an object of class int in /in/LnQvW on line 3
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting ')' in /in/LnQvW on line 3
Process exited with code 255.