-
Notifications
You must be signed in to change notification settings - Fork 540
Check printf parameter types #3977
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check printf parameter types #3977
Conversation
8866323
to
9a4e490
Compare
9a4e490
to
ca3477d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit skeptical here. I think that a lot more types should be allowed in the placeholders. There are probably many combinations allowed by PHP but disallowed by this new rule. For example - you're allowing only int in %d
but it also allows float
: https://3v4l.org/XOB5o
If it's not the case, the message |
ca3477d
to
fd12705
Compare
I improved the error messages. The rule allows passing Some edge-cases:
Tests (8.2, ubuntu-latest) fail, but it seems to be unrelated to my PR ( |
7e59347
to
89641e5
Compare
Thank you! |
Motivation: I refactored code to use
BcMath\Number
instead offloat
, and I didn't notice a printf usage with%f
, which lead to incorrect result. PHPStan didn't complain, becauseBcMath\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:
int
for%d
,int|float
for%f
,__stringandstringable
for%s
. This may be too strict for default PHPStan, but IMO it would be a good candidate for phpstan-strict-rules.vprintf
/vsprintf
.