RE: [PHP-DEV] [POC - Patch] Scalar Type Hinting - A-La zend_parse_parameters
| From: | John Crenshaw | Date: | Fri, 09 Mar 2012 13:21:24 +0000 |
| Subject: | RE: [PHP-DEV] [POC - Patch] Scalar Type Hinting - A-La zend_parse_parameters | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-58818@lists.php.net to get a copy of this message | ||
> > (Now, it would be nice to have another RFC about custom object casting
> > to int, float and bool...)
>
> You mean like https://wiki.php.net/rfc/object_cast_to_types
> which is still in draft?
>
> Note that __toBool would be problematic, since it would be called if the object was used in an
> if statement, which could yield some very strange results if it returned false (it would break the
> existing semantics about how we can use if statements to determine if the type is populated)...
>
> Anthony
And yet, __toBool probably sits right next to __toArray in terms of the level of usefulness (maybe
even beats it.) isset() can always be used to determine whether something was ACTUALLY set to a
non-null value, and to some extent there is already a semantic problem anyway since things like
if("0") resolve to false.
John Crenshaw
Priacta, Inc.