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

(s)printf basic param type validation #9818

Open
kkmuffme opened this issue May 25, 2023 · 1 comment
Open

(s)printf basic param type validation #9818

kkmuffme opened this issue May 25, 2023 · 1 comment

Comments

@kkmuffme
Copy link
Contributor

kkmuffme commented May 25, 2023

When the first param of (s)printf is a literal string (otherwise not possible to validate in psalm):

https://psalm.dev/r/7749cadcab

  • for %d (or %1$d) the corresponding param must be type int (as string will be returned as 0 and float as int)
  • this applies not only to "d" but to [bcdouxX]
  • if placeholder is any of [eEfFgGhH] type should be float
  • if placeholder is s should be type string (if we want to be less strict allow int|float|string like now)

Would be the next step after #9817

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/7749cadcab
<?php

function foo( string $arg ) {
 	printf( 'hello %d', $arg );
}
Psalm output (using commit b99857c):

INFO: MissingReturnType - 3:10 - Method foo does not have a return type, expecting void

kkmuffme added a commit to kkmuffme/psalm that referenced this issue May 30, 2023
Fix vimeo#9819
This PR is a starting point for improving the sprintf return type and eventually validate the format, param types and param count.
(see vimeo#9817, vimeo#9818)
kkmuffme added a commit to kkmuffme/psalm that referenced this issue May 30, 2023
Fix vimeo#9819
This PR is a starting point for improving the sprintf return type and eventually validate the format, param types and param count.
(see vimeo#9817, vimeo#9818)
kkmuffme added a commit to kkmuffme/psalm that referenced this issue May 30, 2023
Fix vimeo#9819
This PR is a starting point for improving the sprintf return type and eventually validate the format, param types and param count.
(see vimeo#9817, vimeo#9818)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants