Skip to content
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

sprintf with float modifier is not considered as numeric-string on "subcalls" #7387

Closed
kissifrot opened this issue Jun 3, 2022 · 4 comments · Fixed by phpstan/phpstan-src#1410

Comments

@kissifrot
Copy link

Bug report

When called directly, a sprintf() with float modifier is correctly considerd as numeric-string.
However, when called indirectly (sorry I can't find the correct word to describe it), looks like infered type is lost and we get non-empty-string instead

Code snippet that reproduces the problem

https://phpstan.org/r/546a013a-1028-41d6-9256-2528c6123498

Expected output

Both calls should yield the same result

Did PHPStan help you today? Did it make you happy in any way?

This tool saved me quite oa lot of problems :)

@ondrejmirtes
Copy link
Member

There's no logic in PHPStan that would infer sprintf('%.14F', $percentage) to always be a numeric-string... Try is_numeric() type narrowing: https://phpstan.org/writing-php-code/narrowing-types

@kissifrot
Copy link
Author

kissifrot commented Jun 3, 2022

That's right, but from a developer's point of view it looks strange to check if sprintf('%.14F') is numeric 😉

@staabm
Copy link
Contributor

staabm commented Jun 4, 2022

Will work on the sprintf thing, after my currently open work in progress landed

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants