RE: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening)
| From: | Christian Stoller | Date: | Thu, 17 Jul 2014 13:00:32 +0000 |
| Subject: | RE: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening) | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-75669@lists.php.net to get a copy of this message | ||
> - I'd like to have E_CAST on all castings/type jugglings even if we do
> not get scalar type hinting.
$var = 6.3;
$a = (int) $var;
Or $b = (bool) "1";
This is usual code and it could be wanted to losse information on casting. Triggering errors for
that would be extremely annoying.
> - I propose to say/implement "scalar parameter casting" instead of
> "scalar type hinting" with a casting syntax:
>
> function foo( (int) $i, ...)
That's bad to read, destroys the possibility to integrate method overloading one day in the
future, and it is telling the wrong story.
If I have "function moo(int $var)" it shows that the method expects an integer.
If I have "function moo((int) $var)" it looks like: Give me whatever you want and I cast
it into an integer.
Christian