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

support positional arguments in sprintf() constant format inference #1437

Merged
merged 2 commits into from Jun 18, 2022

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Jun 17, 2022

re-submit of a previous PR which had to be backed out because of php warnings, see #1426 (comment)

// The printf format is %[argnum$][flags][width][.precision]
if (preg_match('/^%([0-9]*\$)?[0-9]*\.?[0-9]+[bdeEfFgGhHouxX]$/', $formatType->getValue(), $matches) === 1) {
// invalid positional argument
if (array_key_exists(1, $matches) && $matches[1] === '0$') {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this array-key-exists check now prevents the warning we saw earlier:

Warning: Undefined array key 1 in /Users/ondrej/Development/phpstan/src/Type/Php/SprintfFunctionDynamicReturnTypeExtension.php on line 49
PHP Warning:  Undefined array key 1 in /Users/ondrej/Development/phpstan/src/Type/Php/SprintfFunctionDynamicReturnTypeExtension.php on line 49

@staabm staabm marked this pull request as ready for review June 17, 2022 16:41
@ondrejmirtes ondrejmirtes merged commit 8801edb into phpstan:1.7.x Jun 18, 2022
@ondrejmirtes
Copy link
Member

Thank you.

@staabm staabm deleted the sprintf branch June 18, 2022 06:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants