1.2.1456. Wrong Type Returned¶
The returned value is not compatible with the specified return type.
<?php
// classic error
function bar() : int {
return 'A';
}
// classic static error
const B = 2;
function bar() : string {
return B;
}
// undecideable error
function bar($c) : string {
return $c;
}
// PHP lint this, but won't execute it
function foo() : void {
// No return at all
}
?>
See also Returning values, Void Return Type, Mismatch Type And Default and Wrong Typed Property Default.
1.2.1456.1. Suggestions¶
Match the return type with the return value
Remove the return expression altogether
Add a typecast to the returning expression
1.2.1456.2. Specs¶
Short name |
Functions/WrongReturnedType |
Rulesets |
All, Analyze, CE, CI-checks, Changed Behavior, Class Review, LintButWontExec |
Exakat since |
1.8.7 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
High |
Note |
This issue may lint but will not run |
Available in |