Skip to content

Fix counting *scanf() format string placeholders#5594

Open
hakre wants to merge 2 commits intophpstan:2.1.xfrom
hakre:patch-1
Open

Fix counting *scanf() format string placeholders#5594
hakre wants to merge 2 commits intophpstan:2.1.xfrom
hakre:patch-1

Conversation

@hakre
Copy link
Copy Markdown

@hakre hakre commented May 3, 2026

Update PrintfHelper.php:

Make public function getScanfPlaceholdersCount(string $format): ?int returning the sscanf() vetted number of placeholders that give/return/assign conversions.

refs:

@hakre hakre force-pushed the patch-1 branch 4 times, most recently from 57da830 to 5742f2b Compare May 3, 2026 19:24
@hakre hakre marked this pull request as draft May 5, 2026 19:34
@hakre hakre changed the title Counting sscanf/fscanf format string placeholders Fix counting sscanf/fscanf format string placeholders May 5, 2026
@hakre hakre marked this pull request as ready for review May 6, 2026 02:59
@phpstan-bot
Copy link
Copy Markdown
Collaborator

This pull request has been marked as ready for review.

Comment thread src/Rules/Functions/PrintfHelper.php Outdated
Comment thread tests/PHPStan/Rules/Functions/data/printf.php Outdated
@hakre hakre changed the title Fix counting sscanf/fscanf format string placeholders Fix counting *scanf() format string placeholders May 6, 2026
@hakre
Copy link
Copy Markdown
Author

hakre commented May 6, 2026

Do you know by chance why https://github.com/phpstan/phpstan-src/actions/runs/25431166468/job/74597885107 keeps failing on my changes? I'd like to better understand @staabm

@hakre hakre requested a review from staabm May 6, 2026 12:20
@staabm
Copy link
Copy Markdown
Contributor

staabm commented May 6, 2026

Do you know by chance why phpstan/phpstan-src/actions/runs/25431166468/job/74597885107 keeps failing on my changes?

we see the same errors on others PRs targeting 2.1.x -> this means these errors are not related to your PR

Additional by-catch fix of a variable misnomer in 023fa08 ("Fix printf
parameters rule", 2017-04-02) spotted during review.
@hakre hakre force-pushed the patch-1 branch 4 times, most recently from 4bd3eca to 04f1759 Compare May 6, 2026 22:20
Update PrintfHelper.php to make

    public function getScanfPlaceholdersCount(string $format): ?int`

return the sscanf() vetted number of placeholders that return/assign
conversions.

Addresses long-standing regressions reported originally in
[phpstan-10260].

References:

- [phpstan-10260]
- phpstan/phpstan#10260 (comment)
- [phpstan-src-5591]
- [phpstan-14567]
- https://3v4l.org/WR85Q

[phpstan-10260]: phpstan/phpstan#10260
[phpstan-src-5591]: phpstan#5591
[phpstan-14567]: phpstan/phpstan#14567
use const PHP_INT_MAX;
use const PHP_VERSION_ID;

#[CoversMethod(PrintfHelper::class, 'getScanfPlaceholdersCount')]
Copy link
Copy Markdown
Contributor

@staabm staabm May 7, 2026

Choose a reason for hiding this comment

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

we don't use Covers*/Uses* attributes. please remove them.

return new PhpVersion($versionId);
}

public static function dataLegacyVersionIds(): Generator
Copy link
Copy Markdown
Contributor

@staabm staabm May 7, 2026

Choose a reason for hiding this comment

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

what is this complicated method doing? couldn't we just have a data-provider which returns a few representative "hard-coded" data-pairs ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants