Няяяяяяяяяяяяяяяяяяяяя.. Скаляры!! ))
PHP:
keeper@keeper:~$ cat php7.php
<?php
function hello(int $int): string {
return $int . " monkeys";
}
function hello_num(int $int): string {
return $int;
}
function hello_int(string $int): int {
return $int;
}
var_dump( hello(2) );
var_dump( hello(3.2) );
var_dump( hello("4") );
var_dump( hello("4names") );
#var_dump( hello(fopen("/tmp/hello", "w+")) ); // Argument 1 passed to hello() must be of the type integer, resource given, called in /home/keeper/php7.php on line 12 and defined in /home/keeper/php7.php on line 3
#var_dump( hello_num("Hello!") ); // Fatal error: Argument 1 passed to hello_num() must be of the type integer, string given, called in /home/keeper/php7.php on line 24 and defined in /home/keeper/php7.php on line 8
var_dump( hello_int("4You too!") );
#var_dump( hello_int("You too!") ); // Fatal error: Return value of hello_int() must be of the type integer, string returned in /home/keeper/php7.php on line 15 in /home/keeper/php7.php on line 15
Код:
keeper@keeper:~$ /opt/php7/compiled/bin/php php7.php
string(9) "2 monkeys"
string(9) "3 monkeys"
string(9) "4 monkeys"
string(9) "4 monkeys"
int(4)