Re: Make strict mode more strict?
| From: | Rowan Collins | Date: | Wed, 16 Sep 2015 23:17:49 +0000 |
| Subject: | Re: Make strict mode more strict? | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-88272@lists.php.net to get a copy of this message | ||
On 16 September 2015 23:10:55 BST, Yasuo Ohgaki <yohgaki@ohgaki.net> wrote:
>The idea is as follows:
>
><?php
>declare(strict_types=1);
>
>function foo(int &$i) {
> $i = "string"; // Raise error
> $i = function_returns_string(); // Raise error
> $i = 1234.5678; // Raise error
> $i = function_returns_float(); // Raise error
I think the problem here would be the same as with declaring types on object properties - it would
require a major change to how the engine works so that every assignment operation had a potential
for type checking, and strictness could stick to variables.
The reason the current type annotations can be enforced more easily is that they exist only on the
boundary of a function, where variables are being copied into local parameters, and the function
signature can readily hold the metadata.
There is also the question from the language design point of view of whether this is too
"un-PHP-like". If you want something like PHP but with full type annotations, try Hack.
Regards,
--
Rowan Collins
[IMSoP]