A %s with return type must return a value
Description
When a function or a method declares a return type, every return statement in its body must provide a value, unless the type accepts no returned value (void, never) or the type allows null.
Writing a bare return;, without an expression, is only valid when the declared return type permits the absence of a value. Here, int does not, so the engine cannot supply an implicit value.
This is a compile time check: it does not depend on the code being executed.
Example
<?php
function foo(): int {
return;
}
?>
Alternatives
- Add a value to the return statement, matching the declared return type.
- Remove the return type, if the function is not meant to return a value.
- Change the return type to
voidif the function is not meant to return a value.
Related error messages
Changed Behavior
This error may appear following an evolution in behavior, in previous versions. See