Re: return false if error
| From: | Adam Harvey | Date: | Wed, 19 Mar 2014 01:16:05 +0000 |
| Subject: | Re: return false if error | ||
| References: | 1 2 | Groups: | php.doc |
| Request: | Send a blank email to phpdoc+get-969384877@lists.php.net to get a copy of this message | ||
On 18 March 2014 17:52, Hannes Magnusson <hannes.magnusson@gmail.com> wrote:
> On Tue, Mar 18, 2014 at 2:06 PM, Robert Stoll <php@tutteli.ch> wrote:
>>
>> 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.
>
> Interesting.
>
> I don't know why or when strpos docs got changed to 'mixed', that
> definitely is not how it was originally:
> http://www.php.net/manual/en/about.prototypes.php
I'd argue strpos is mixed, since it can return either an integer or
boolean for valid arguments.
In the general case, I agree that we shouldn't change functions to
mixed just because they return null when given an invalid argument,
though.
Adam