1.2.80. Bad Type Relay¶
A bad type relay happens where a types argument is relayed to a parameter with another type. This leads to a Fatal error, and stops execution. This is possibly a piece of dead code.
It is recommended to harmonize the types, so the two methods are compatible.
<?php
// the $i argument is relayed to bar, which is expecting a string.
function foo(int $i) : string {
return bar($i);
}
// the return value for the bar function is not compatible with the one from foo;
function bar(string $s) : int {
return (int) $string + 1;
}
?>
1.2.80.1. Suggestions¶
Harmonize the type so they match one with the other.
Remove dead code
Apply type casting before calling the next function, or return value
1.2.80.2. Specs¶
Short name |
Functions/BadTypehintRelay |
Rulesets |
|
Exakat since |
1.6.6 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
High |
Features |
type |
Available in |