Repository navigation
Resolve constants in attributes of class members in the class namespace - #260
Merged
Merged
Conversation
Member
Author
|
rebase to 4.x please |
…mespace ReflectionMethod::getAttributes() failed for unqualified constants (true, false, null, PHP_INT_MAX, namespaced constants): NodeExpressionResolver looked them up in the namespace of the method itself, which is always '' (like the native reflection), so ReflectionFileNamespace threw "Namespace was not found" (or a ValueError for an empty path when the method was reflected on its own and had no file name). The resolver now takes the namespace and the file from the reflector that owns the code: the declaring class for methods, properties and class constants (the trait for imported trait methods), the declaring function or class for parameters. This also makes __NAMESPACE__, __FILE__ and __DIR__ work in these contexts, and skips the namespace lookup for true/false/null (case-insensitively) and for code without a file. Fixes #259 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FxhC1GTbduntXjyF8E9Feb
lisachenko
force-pushed
the
feature/pensive-hypatia-bx7t23
branch
from
November 11, 2026 21:50
0796315 to
f6b20ce
Compare
lisachenko
marked this pull request as ready for review
November 11, 2026 21:51
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.
Fixes #259
Problem
ReflectionMethod::getAttributes()threw for unqualified constants in attribute arguments (true,false,null,PHP_INT_MAX, namespacedconsts).NodeExpressionResolver::resolveExprConstFetch()looked the constant up in the namespace of the context, and a method's namespace is always''(same as native reflection). SoReflectionFileNamespacethrewNamespace was not found in the file …, which is what breaks weaving in goaop/framework. When the method was reflected on its own, its file name was empty too, so you gotValueError: Path must not be emptyinstead.Fix
NodeExpressionResolvernow takes the namespace and file from the reflector that owns the code, through two private helpers,getContextScope()andgetContextFileName():Side effects of the change:
__NAMESPACE__,__FILE__and__DIR__now resolve in these contexts. Before, a method gave''for__NAMESPACE__, and properties, parameters and class constants threw.true/false/null, now matched case-insensitively (soTRUEtoo), and for code with no file name.Tests
New test
tests/ConstantsInMemberAttributesTest.phpwith stubtests/Stub/FileWithConstantsInMemberAttributes.php. It coverstrue/false/null/TRUE/\true, a global constant, a namespaced constant,self::class,__NAMESPACE__, constants inside an array, and trait methods from another namespace. Methods are checked both through their class and on their own; properties, class constants, method parameters, functions and function parameters are covered too. A parity test compares every argument with native reflection once the stub is loaded.4.x(PHPUnit 11): full suite of 13793 tests passes.phpstan analyse src: no errors.opcache.jit=disable, to avoid the tracing-JIT bug in that PHP version. PHP 8.4 is covered by CI.🤖 Generated with Claude Code
https://claude.ai/code/session_01FxhC1GTbduntXjyF8E9Feb