Re: RE: [VOTE][RFC] Coercive Scalar Type Hints
| From: | Anthony Ferrara | Date: | Wed, 11 Mar 2015 18:28:01 +0000 |
| Subject: | Re: RE: [VOTE][RFC] Coercive Scalar Type Hints | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-84567@lists.php.net to get a copy of this message | ||
Zeev,
>> You also stated above that false->bool is not supported (I'm guessing
> you
>> meant float->bool). So users would be able to pass "4.3" to a bool
> typehint,
>> but not 4.3? This behavior seems very arbitrary and confusing.
>
> It may be confusing, but only academically so. Again, this approach tries
> to work well with real world usage - and reject conversions which are
> likely to be erroneous. "4.3" may look like a floating point number but
> in the context of conversion to boolean, that doesn't matter much. It's a
> string.
Doesn't that contradict what you've been saying the whole time about
how "13" and 13 and 13.0 are really "the same thing", and as such
should be coerced?
> function bar(float $x)
> $foo = 1;
> bar($foo); // will definitely fail in strict mode
No, actually it won't fail in strict mode:
https://wiki.php.net/rfc/scalar_type_hints_v5#integers_should_be_accepted_for_strict_float_arguments
Anthony