return false if error
| From: | Robert Stoll | Date: | Tue, 18 Mar 2014 21:06:34 +0000 |
| Subject: | return false if error | ||
| Groups: | php.doc | ||
| Request: | Send a blank email to phpdoc+get-969384873@lists.php.net to get a copy of this message | ||
Heya,
We were discussing the scenario where a function returns false in an error case in a thread on the
general mailing list.
I always thought the documentation would use mixed as return type in such a situation (like in
strpos) but others
disagreed.
For instance, Mike Ford told me:
> It has always been policy in the documentation to specify only the substantive return type(s)
> of a function
> in the signature, and only mention return of "false" as an error indicator in the
> description. There are
> many, many examples of this in the manual, and I think it's unlikely the policy will
> change any time soon.
So my question is, what is your opinion on that topic?
I already committed two patches to change the return type to mixed, since the functions also return
false.
I could revert them (or discard the commit, I do not know if this is possible - was made through
edit.php.net).
IMO the most important thing is that the documentation is consistent. Either change all such
functions to mixed or
change strpos to int (and probably further functions as well).
Or we go a new path and add a construct which indicates that a function returns false as well.
For instance:
int! strpos ( string $haystack , mixed $needle [, int $offset = 0 ] )
where int! stands for int or false if an error occurs.
Cheers,
Robert