<?php
interface ICommand {
public function execute() : string;
}
class Test {
public function execute(string $val) : int {
return 'asd ' . $val;
}
}
$t = new Test();
echo $t->execute('sample val');
Fatal error: Uncaught TypeError: Test::execute(): Return value must be of type int, string returned in /in/nXa7u:9
Stack trace:
#0 /in/nXa7u(14): Test->execute('sample val')
#1 {main}
thrown in /in/nXa7u on line 9
Process exited with code 255.
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Fatal error: Uncaught TypeError: Return value of Test::execute() must be of the type int, string returned in /in/nXa7u:9
Stack trace:
#0 /in/nXa7u(14): Test->execute('sample val')
#1 {main}
thrown in /in/nXa7u on line 9
Process exited with code 255.
Fatal error: Uncaught TypeError: Return value of Test::execute() must be of the type integer, string returned in /in/nXa7u:9
Stack trace:
#0 /in/nXa7u(14): Test->execute('sample val')
#1 {main}
thrown in /in/nXa7u on line 9
Process exited with code 255.
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
Parse error: syntax error, unexpected ':', expecting ';' or '{' in /in/nXa7u on line 4
Process exited with code 255.