Re: [RFC] Scalar Type Hinting With Casts (re-opening)
| From: | Andrea Faulds | Date: | Sun, 13 Jul 2014 18:21:09 +0000 |
| Subject: | Re: [RFC] Scalar Type Hinting With Casts (re-opening) | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-75434@lists.php.net to get a copy of this message | ||
On 13 Jul 2014, at 18:56, Larry Garfield <larry@garfieldtech.com> wrote:
> We can discuss when the E_* should be emitted separately from what the cast result is.
Is there any actual controversy over what the *result* of casts should be. This RFC just has the
normal casting result. Is anyone really in disagreement there?
> As long as it's an error of some kind it may be OK, but perhaps we want to leave array as
> is (strict behavior) rather than changing it to the primitive logic (cast behaviour)?
I think the discussion about how arrays should be casted too for consistency is a bit silly. What
makes sense for non-scalar types (strict hinting) may not work so well for scalar types; casting to
array is rarely useful, while casting to the scalar types is readily. Also, frankly, function
foobar((int) $a, array $b) is inconsistent and ugly.
Note too that the non-scalar types, while they can be casted from, can’t always be casted to. You
can cast to an object, but only StdClass, and you can’t cast to resource at all.
I really don’t think there’s anything wrong with having one system for the scalar types and one
for the non-scalar types since they’re so different.
--
Andrea Faulds
http://ajf.me/