Skip to content

Resolve the printf format parser's PHP version check from Scope::getPhpVersion() - #6536

Merged
staabm merged 1 commit into
phpstan:2.3.xfrom
phpstan-bot:create-pull-request/printf-format-parser-scope-php-version
Sep 22, 2026
Merged

staabm merged 1 commit into
phpstan:2.3.xfrom
phpstan-bot:create-pull-request/printf-format-parser-scope-php-version

Conversation

@staabm

@staabm staabm commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

PrintfFormatParser asked a DI-injected PhpVersion whether the h/H specifiers are supported. That object only knows the single version configured in phpstan.neon, so it ignored both PHP_VERSION_ID narrowing in the analysed code and a configured phpVersion range.

parse() now takes the call site's PhpVersions, which every caller reads from Scope::getPhpVersion(), and treats the specifiers as valid unless the analysed range certainly predates PHP 8.0.

…hpVersion()

PrintfFormatParser asked a DI-injected PhpVersion whether the h/H specifiers
are supported. That object only knows the single version configured in
phpstan.neon, so it ignored both PHP_VERSION_ID narrowing in the analysed code
and a configured phpVersion range.

parse() now takes the call site's PhpVersions, which every caller reads from
Scope::getPhpVersion(), and treats the specifiers as valid unless the analysed
range certainly predates PHP 8.0.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@staabm
staabm force-pushed the create-pull-request/printf-format-parser-scope-php-version branch from b4545dc to 1420645 Compare September 22, 2026 13:16
@staabm
staabm merged commit 4a7bb14 into phpstan:2.3.x Sep 22, 2026
544 of 551 checks passed
@staabm
staabm deleted the create-pull-request/printf-format-parser-scope-php-version branch September 22, 2026 13:36
phpstan-bot added a commit to phpstan-bot/phpstan-src that referenced this pull request Sep 22, 2026
The printf format parser change was split off into phpstan#6536, which has since
been merged into the base branch. Reverting it on this branch therefore
undid already-merged work instead of separating it, so the parser keeps
parse(string $format, PhpVersions $phpVersions) and the rules keep passing
Scope::getPhpVersion().

PrintfFunctionThrowTypeExtension keeps this pull request's own change:
its throwsValueErrorForInternalFunctions() check resolved from the Scope.

This reverts commit fba0257.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
staabm pushed a commit to phpstan-bot/phpstan-src that referenced this pull request Sep 22, 2026
The printf format parser change was split off into phpstan#6536, which has since
been merged into the base branch. Reverting it on this branch therefore
undid already-merged work instead of separating it, so the parser keeps
parse(string $format, PhpVersions $phpVersions) and the rules keep passing
Scope::getPhpVersion().

PrintfFunctionThrowTypeExtension keeps this pull request's own change:
its throwsValueErrorForInternalFunctions() check resolved from the Scope.

This reverts commit fba0257.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.

2 participants