RE: [PHP-DEV] RE: [VOTE][RFC] Coercive Scalar Type Hints
| From: | Derick Rethans | Date: | Wed, 11 Mar 2015 20:37:26 +0000 |
| Subject: | RE: [PHP-DEV] RE: [VOTE][RFC] Coercive Scalar Type Hints | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-84574@lists.php.net to get a copy of this message | ||
On Wed, 11 Mar 2015, Zeev Suraski wrote:
> From: Anthony Ferrara [mailto:ircmaxell@gmail.com]
>
> > > function bar(float $x)
> > > $foo = 1;
> > > bar($foo); // will definitely fail in strict mode
> >
> > No, actually it won't fail in strict mode:
> > é1í
> > Ëq�Jžä|gÐ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
And it should fail, as logically it is the same as:
$foo = 1.901 - 0.709 - 0.192;
bar($foo);
which is only 1, if you look at it with a small enough precision.
cheers,
Derick