Re: JIT (was RE: [PHP-DEV] Coercive Scalar Type Hints RFC)
| From: | Stanislav Malyshev | Date: | Mon, 23 Feb 2015 02:32:37 +0000 |
| Subject: | Re: JIT (was RE: [PHP-DEV] Coercive Scalar Type Hints RFC) | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-83533@lists.php.net to get a copy of this message | ||
Hi!
> How is coercive much smarter? Basically what coercive would do is
It can accept 2.0 but not 2.5. Explicit cast is a sledgehammer - it
would convert both to 2.
> How casting (int) could be such dangerous thing? Lets take for example
> this code:
>
> echo (int) "whats cooking!";
> echo intval("whats cooking");
>
> Both statements print 0, so how is casting unsafe???
Casting by itself is not dangerous. What is dangerous is using casting
to work around type system - since in this case it could hide an error
(such as passing string "whats cooking!" to function requiring integer).
Of course, you can say such errors are of no importance to you - in
which case you should never use typed parameters at all and you'll be
fine :) (mostly)
--
Stas Malyshev
smalyshev@gmail.com