Skip to content

Fix global constant discovery after class name tokens - #6756

Open
LubuSeb wants to merge 4 commits into
phpstan:2.3.xfrom
LubuSeb:codex/fix-class-token-symbol-scan
Open

LubuSeb wants to merge 4 commits into
phpstan:2.3.xfrom
LubuSeb:codex/fix-class-token-symbol-scan

Conversation

@LubuSeb

@LubuSeb LubuSeb commented Oct 16, 2026 •

Copy link
Copy Markdown

When a global constant follows stdClass::class inside a function, the directory symbol scan can mistake the class name token for a declaration and lose the constant. The same can happen with identifiers beginning with class. This change checks the keyword boundary before entering type scope in both the PHP cleaner and the Turbo scanner.

The regression covers ::class, className(), and a real anonymous class. The native differential corpora also include the trigger. Thanks to @Victor-emil for identifying the cause and suggesting the boundary check in phpstan/phpstan#15482.

Validation: the focused PHPUnit test passes (3 tests); the source-locator suite passes (78 tests, 159 assertions, 1 skip); and the issue's two-file example analyzes without errors using this branch. PHP syntax and git diff --check pass. I could not run the native differential scripts locally because the Turbo extension is not installed.

Fixes phpstan/phpstan#15482

@LubuSeb

LubuSeb commented Oct 16, 2026

Copy link
Copy Markdown
Author

CI note: the result-cache-parse-error E2E check is failing on this PR, but the same check failed on the untouched 2.3.x base commit before this PR. Its final assertion expects a circular-reference error and gets exit 0. I have not changed that E2E case or the relevant result-cache code.

The PHP 7.4 call syntax and Turbo version-pin failures from my first push have been corrected in the current head.

@LubuSeb
LubuSeb force-pushed the codex/fix-class-token-symbol-scan branch from 5279933 to bba1cf7 Compare October 18, 2026 12:56
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.

Global constant "not found" when an earlier function body in its file uses ::class

1 participant