Skip to content

Un-prefix Filter\ and PDO\ class name strings in the phar - #6512

Merged
ondrejmirtes merged 1 commit into
2.2.xfrom
scoper-unprefix-filter-pdo
Sep 22, 2026
Merged

ondrejmirtes merged 1 commit into
2.2.xfrom
scoper-unprefix-filter-pdo

Conversation

@ondrejmirtes

@ondrejmirtes ondrejmirtes commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

php-scoper prefixes namespaced string literals such as new ObjectType('Filter\FilterFailedException') even when they name internal PHP classes. The phpstorm-stubs are only consulted for real class references, not for strings, so updating them in compiler/box does not help. As a result the phar reports _PHPStan_<sha>\Filter\FilterFailedException in missingType.checkedException, and PDO::connect() returns prefixed PDO\Mysql, PDO\Pgsql, … class names.

  • Filter and PDO are added to the namespaces the src/ patcher un-prefixes, next to BcMath, Dom, FFI and Ds.
  • The list lives in the new compiler/build/scoper-namespaces.php together with exclude-namespaces, so ScoperClassNameStringsTest can fail whenever src/ gains a class name string in a namespace that is neither excluded nor un-prefixed.
  • Foobar\Buz in ErrorFormatterTestCase is covered by the generic patcher instead of its one-off.

Verification: built the phar (PHAR_CHECKSUM=1) before and after this change and diffed the extracted contents. Only FilterVarThrowTypeExtension.php (1 literal) and PDOConnectReturnTypeExtension.php (6 literals) differ, and the issue's snippet no longer reports the prefixed class.

Split out of #6112. The argument.invalidConstant error from the same snippet is fixed in #6513.

Closes phpstan/phpstan#15007

🤖 Generated with Claude Code

https://claude.ai/code/session_01SCH8hvECi7zaEUr1Get7sG

php-scoper prefixes namespaced string literals such as
`new ObjectType('Filter\FilterFailedException')` even when they name
internal PHP classes, so the phar reported
`_PHPStan_<sha>\Filter\FilterFailedException` and returned prefixed
`PDO\*` subclasses from `PDO::connect()`.

The namespaces un-prefixed by the patcher now live in
compiler/build/scoper-namespaces.php, shared with a test that fails when
src/ contains a class name string whose namespace is not handled.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SCH8hvECi7zaEUr1Get7sG
@ondrejmirtes
ondrejmirtes merged commit 8f06875 into 2.2.x Sep 22, 2026
493 of 495 checks passed
@ondrejmirtes
ondrejmirtes deleted the scoper-unprefix-filter-pdo branch September 22, 2026 09:09
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.

1 participant