Type Is Not Always Returned
<?php
class x implements y {
function foo(): bool {
throw new exception('Ah!');
}
}
interface y {
function foo(): bool;
}
?>
A method can display a return type, and never return it actually. This happens with exceptions, errors, yield and infinite loops. May be ‘never’ would be a better choice, if possible.
On the other hand, a function returning ‘void’, aka returning nothing, should not have any return statement, including the hidden one at the end of the method.
See Also
PHP Features
Last updated: 10 September 2026