Repository navigation
Conversation
@PARAM PHP_ROUND_* $mode now resolves to the union of the global constants the pattern matches, 1|2|3|4, the way @PARAM Foo::BAR_* does for class constants. Like PHP does for an unqualified constant name, an unqualified pattern looks in the current namespace first and falls back to the global one; a qualified one is resolved like a class name. A pattern matching nothing is an unresolvable type. ReflectionProvider::findConstantNames() finds the matching constants among the built-in ones from the stubs, the ones defined at runtime and the ones declared in the analysed and scanned files, keeping only those the configured PHP version has. Needs phpstan/phpdoc-parser to read such a pattern. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The PHPDoc-level tests need phpstan/phpdoc-parser to read PHP_ROUND_*, and that change cannot be merged before this one: its downstream test of this repository already meets @PARAM FILTER_VALIDATE_* in tests/PHPStan/Analyser/nsrt/filter-*.php and throws without it. So this tests TypeNodeResolver on the node that change produces, and the PHPDoc tests come back with the phpdoc-parser bump. Co-Authored-By: Claude Opus 5.5 <[email protected]>
gnutix
marked this pull request as ready for review
November 7, 2026 10:50
Collaborator
|
This pull request has been marked as ready for review. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@param PHP_ROUND_* $modenow resolves to the union of the global constants the pattern matches (1|2|3|4), the way@param Foo::BAR_* $xdoes for class constants.Merge this before phpstan/phpdoc-parser#342, which makes such a pattern parse (it is an invalid PHPDoc today). That PR's downstream job runs this repository's tests on
2.3.xwith the new parser, and existing tests already contain@param FILTER_VALIDATE_* $intFilter(tests/PHPStan/Analyser/nsrt/filter-*.php), which throwsShouldNotHappenExceptionwithout this change. Merging this first is harmless: the current parser never produces a class-lessConstFetchNodewith a*.So the test here (
TypeNodeResolverTest) resolves the node that phpdoc-parser change produces, without needing the parser. The PHPDoc-level tests (annsrtfile and an unresolvable-type rule test) come in a follow-up with the phpdoc-parser bump; I ran them locally against the patched parser, along with the whole suite.What it enables once the parser reads it:
How it works:
TypeNodeResolverresolves the pattern. Like PHP does for an unqualified constant name, an unqualified pattern looks in the current namespace first and falls back to the global one; a qualified one is resolved like a class name. Each match goes throughConstantResolver, so its type is what fetching that constant gives (dynamicConstantNamesincluded).ReflectionProvider::findConstantNames()is new. The interface is@api-do-not-implement, so adding a method keeps the BC promise.BetterReflectionProvidermatches the pattern against the names from the stubs map,get_defined_constants()andreflectAllConstants(), keeping only the constants the configured PHP version has.Costs and limits worth a look:
reflectAllConstants()parses every analysed or scanned file that declares a global constant, once per process and only when a global wildcard is used. On this repository's test container that is 51 files, +29 MB and 0.4 s. A cheaper path would list constant names straight from the symbol scan of the directory locators, but that needs a names-only API through the source locator wrappers, so I left it out.Foo::BAR_*has the same gap today.@param PHP_ROUND_HALF_UP $x) is still read as a class name; only patterns are new.CI: the Larastan, phpstan-dba and phpstan-laravel integration jobs fail with float typing differences (
numeric-string→non-empty-stringfor a quoted float,float|null→float<0.0, 3037000499.97605>|null), unrelated to this change. They come from #6993 (now 4a6e0e9 on2.3.x), which failed the same three jobs, and they fail the same way on #6994.Closes phpstan/phpstan#7272
🤖 Generated with Claude Code