phpstan-src icon indicating copy to clipboard operation
phpstan-src copied to clipboard

fix parameter of strval, intval and floatval

Open Khartir opened this issue 3 years ago • 2 comments

resolves https://github.com/phpstan/phpstan/issues/6560

I implemented a rule instead of a dynamic return type extension as mentioned in https://github.com/phpstan/phpstan/issues/6560#issuecomment-1032304276. I think that was a misunderstanding? After all the problem is the parameter type, not the return type of the function. For the return type StrvalFamilyFunctionReturnTypeExtension already exists.

Khartir avatar Feb 08 '22 18:02 Khartir

Errr, I thought that you want to implement a dynamic return type extension so that the result type of floatval($val) is the same as (float) $val.

If you need to check the parameter type then sure, a change in functionMap would be sufficient.

ondrejmirtes avatar Feb 09 '22 08:02 ondrejmirtes

After changing the functionMap I had to completely rewrite the rule to only check Stringable objects, since intval and floatval accept string, but no objects.

Khartir avatar Feb 10 '22 18:02 Khartir