RE: Mixed return type - boolean and array/resource/closure or object

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




> -----Original Message-----
> From: Lester Caine [mailto:lester@xxxxxxxxxxx]
> Sent: Wednesday, March 05, 2014 11:15 PM
> To: php-general@xxxxxxxxxxxxx
> Subject: Re:  Mixed return type - boolean and array/resource/closure or object
> 
> Robert Stoll wrote:
> >>> Nevertheless, the signature in the documentation implies that
> >>> date_create() returns always DateTime. I already submitted a patch to
> >>> change it to mixed :)
> >>
> >> IMHO, the signature is fine, as false is returned only in *exceptional*
> >> cases.  To be strict, changing the return type to mixed had to be done
> >> for (nearly) *all* functions, because several may return false in error
> >> cases, and many will return null when wrong arguments are passed.
> 
> > I see your point. But IMO it is confusing that something else is returned than mentioned in the signature. I always
take
> > strpos as a reference (it has mixed as return type). Yet, mixed is not really precise and I think it would be better
to
> > have something like "int|false" or a shorter form, maybe "int!" to indicate that either int or false is returned.
> >
> > Changing strpos to int would be wrong IMO. I want to see at one glance from the signature of the function what it
> > returns. As I said mixed is not ideal either since I have to scroll down to 'Return Values' but better than
confusing
> > me.
> I try as much as possible to list the various return options in the docblock
> function header which is fine where I'm working with everything via an IDE which
> simply uses it as a type hint. This goes back to PHP4 days and still works
> perfectly well without needing anything more complex. Tweaking the formal help
> to match that works for me.
> 
> > About null, I see null as part of an object type. I know that many people would not agree on this one but for me it
> > makes sense.
> Data returned from databases uses 'null' for the specific instance of 'not set'
> and while you could wrap every data field into an object, simply replacing a
> value with 'null' in a results array is totally logical. Binary has two values -
> 'yes', 'no' and 'I don't know' :)
> 
> --
> Lester Caine - G8HFL

I think you wander off the subject. We were talking about built-in functions/methods and not about userland
functions/methods.
The original question was if a function/method exists which returns either a boolean or array/resource/closure/object
and I got already helpful answers - thanks again :)
And the last bit of the discussion was just if the documentation should have "mixed" as return type for such
functions/methods or "array/resource/closure/a specific object"


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux