phpstan-src
phpstan-src copied to clipboard
Check printf parameter types
Motivation: I refactored code to use BcMath\Number instead of float, and I didn't notice a printf usage with %f, which lead to incorrect result. PHPStan didn't complain, because BcMath\Number has __toString().
Here is an executed version of the test file: https://3v4l.org/3pXMc
I left some things for possible future PRs to keep things simple:
- Strict mode: enforce
intfor%d,int|floatfor%f,__stringandstringablefor%s. This may be too strict for default PHPStan, but IMO it would be a good candidate for phpstan-strict-rules. - Handle multiple possibilities for format string.
- Add support for
vprintf/vsprintf.