Re: [RFC] Scalar Type Hinting With Casts (re-opening)
| From: | Rowan Collins | Date: | Wed, 16 Jul 2014 10:34:01 +0000 |
| Subject: | Re: [RFC] Scalar Type Hinting With Casts (re-opening) | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-75585@lists.php.net to get a copy of this message | ||
Stas Malyshev wrote (on 15/07/2014):
Hi!I was thinking of them as explicit within the function definition, rather than within the calling code. I guess a cast always explicitly happens *somewhere*, so it's a matter of interpretation, but this is the rough equivalence which made me think of it as explicit: function foo(int $bar) { } function foo($bar) {That's only a problem if you frame the new hints as "a type of implicit cast". If they were to be described in relation to existing functionality, I'd describe them as a new type of *explicit* cast, butHow they are explicit cast if you're not explicitly casing anything?
$bar = (int)$bar;} In contrast, if you write '123' + '456', you never mention "int" at all, but an implicit cast happens to both arguments.
As far as I know there's only one set of rules at the moment, and I'm suggesting adding a second. So, "kind of OK". Unless I'm missing something about what we currently have.as mentioned elsewhere, I'd be happy for them to exist outside of function signatures too as a new notion of "strict cast".That's exactly what I want to avoid - having several forms of casts with different rules. One is good, two is kind of OK, three is too much.