> -----Original Message-----
> From: Anthony Ferrara [mailto:ircmax...@gmail.com]
> Sent: Wednesday, March 11, 2015 8:28 PM
> To: Zeev Suraski
> Cc: Theodore Brown; internals@lists.php.net
> Subject: Re: [PHP-DEV] RE: [VOTE][RFC] Coercive Scalar Type Hints
>
> 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?

No, it does not.  "13" and 13 and 13.0 are the same thing when you're
expecting an integer, and rejecting "13" as an integer is nothing but noise
in the vast majority of cases - noise that will push towards an explicit
cast.  Strings, however, are treated in a totally different way that places
zero meaning on their numeric value across the entirety of PHP when in the
context of a boolean.

>
> > 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

You're right, sorry.  Reverse it then:
function bar(int $x)
$foo = 1.0;
bar($foo);  // will definitely fail in strict mode

Zeev

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to