-
-
Notifications
You must be signed in to change notification settings - Fork 934
Description
Feature request
PHPStan handles direct casts using (string)
, (int)
and (float)
differently than using the strval()
, intval()
and floatval()
functions, however PHP behaves the same with both methods:
https://phpstan.org/r/62904f7f-1538-422c-a6c4-f3fb53fc40a4
I had hoped to fix this by changing the parameter type of those functions in the functionMap from mixed to the correct union type. However that would require the Stringable
interface to work there, even with older PHP versions. Is this possible or does this require a new rule?
While testing the different cases I also came across another difference in PHPStan and PHP: PHP can cast a resource
to float
, the same way it can cast it to int
. However PHPStan only allows casting to int
and reports an error when casting to float
. I don't see a reason to allow this, I just noticed the difference and wondered if it was intentional.
Did PHPStan help you today? Did it make you happy in any way?
I just realized how much it trains me to write better/cleaner code from the beginning, since I know if I don't, PHPStan will complain and I have to fix it later. So thank you very much for that.