Skip to content

Fix counting sscanf/fscanf format string placeholders#5594

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

Fix counting sscanf/fscanf 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 added 2 commits May 6, 2026 04:38
Make `public function getScanfPlaceholdersCount(string $format): ?int` returning the sscanf() vetted number of placeholders that give/return/assign conversions.

refs:

- phpstan#5591
- phpstan/phpstan#14567
@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.

$throws = $this->phpVersion->throwsValueErrorForInternalFunctions();
try {
if ($throws === false) {
set_error_handler(
Copy link
Copy Markdown
Contributor

@staabm staabm May 6, 2026

Choose a reason for hiding this comment

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

why do we need this error-handler/try-catch construction?
we don't need it in other rules/rule-helpers?

Copy link
Copy Markdown
Contributor

@staabm staabm May 6, 2026

Choose a reason for hiding this comment

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

could we use @sscanf() instead and check the return type?

Comment on lines +38 to +39
sscanf($str, '%.E', $number); // bad scan conversion character '.'
fscanf($str, '%.E', $number); // bad scan conversion character '.'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
sscanf($str, '%.E', $number); // bad scan conversion character '.'
fscanf($str, '%.E', $number); // bad scan conversion character '.'
sscanf($str, '%.E', $number); // bad scan conversion character '.'
fscanf($resource, '%.E', $number); // bad scan conversion character '.'

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