Open Tarmean opened 5 years ago
Type checking is currently restricted to where type declarations have been used, so this could be expanded. Though for the example above, when an assignment has been annotated it usually means that the developer knows better than the type inference, so I'd be reluctant to show an error for this case.
If int
is valid should be also included in @var
. Intelephense shouldn't be weakened because some devs like to write bad code. As I mentioned in #695 this is great place to use declare(strict_types=1)
or config option and warn about type misuses.
Fair enough. Agree that there should be some way of opting in for more thorough checking.
My reasoning is: If someone is using strict_types
he already is trying to follow standards. However I'm expecting cases when strict checks could be desired, when use of declare is not possible (e.g. old projects).
It's a fair point that
/** @var int $foo */
$foo = $json['foo']
would give a warning which might not be wanted.
But I think there are always ways around this. In this case:
assign and only then assert the type to be explicit if you are sure
I like all of these better than the current behavior. Though I might be alone there so I totally understand if this would be opt-in and low priority.
Example:
At the end of this snippet
$str
is inferred asstring
. It'd be really useful if violations to user specified types were highlighted.