Re: [RFC] Safe Casting Functions
| From: | Derick Rethans | Date: | Tue, 21 Oct 2014 15:26:14 +0000 |
| Subject: | Re: [RFC] Safe Casting Functions | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-78205@lists.php.net to get a copy of this message | ||
On Mon, 20 Oct 2014, Andrea Faulds wrote:
> Good evening,
>
> I am presenting a new RFC to add a set of three functions to do validated casts for scalar
> types:
>
> https://wiki.php.net/rfc/safe_cast
>
> Please read it.
> > The functions return FALSE on failure instead of NULL because:
> > - If strict type hinting were added, they would fail for a nullable
> > typehint
> > - FALSE is a traditional error value in PHP
> > - NULL is used to signify the absence of a value - but what we want to
> > signify is an invalid value (similar to 0 vs NaN)
But what about if we also would like a to_bool, which would accept
"true", "false", "0", "1", true, false, 1 and 0?
Then to_bool() whould return false... or true? So hence, it should be
NULL, and that would also be consistent with ext/filter.
cheers,
Derick