In this branch, the function will implicitly return null which is incompatible with the type-hinted return string. Consider adding a return statement or allowing null as return value.
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type.
Let?s take a look at an example:
interfaceReturnsInt{publicfunctionreturnsIntHinted():int;}classMyClassimplementsReturnsInt{publicfunctionreturnsIntHinted():int{if(foo()){return123;}// here: null is implicitly returned}}
It is not recommended to use PHP's closing tag ?> in files other than templates.
Using a closing tag in PHP files that only contain PHP code is not recommended
as you might accidentally add whitespace after the closing tag which would then
be output by PHP. This can cause severe problems, for example headers cannot be
sent anymore.
A simple precaution is to leave off the closing tag as it is not required, and
it also has no negative effects whatsoever.