Repository navigation
fix(proxy): emit fully-qualified parent for classes extending global classes - #762
Merged
Merged
Conversation
…classes A woven namespaced class extending a global class (\ArrayObject, \Exception, ...) got a proxy with `extends ArrayObject`: the reflection parent name has no leading backslash, so ClassGenerator emitted a relative name that resolved in the proxy namespace and loading the proxy failed with `Class "Ns\ArrayObject" not found`. - ClassProxyGenerator roots the reflection parent name, like it already does for the original interfaces; introduced traits and interfaces are rooted too, so direct callers that bypass AdviceMatcher are safe. - ClassGenerator::addTraitAlias() keeps the trait name as given, so a rooted global trait stays fully qualified in its alias adaptation. - The OriginalTrait reference keeps its deliberate short relative name. Tests: weaving snapshot plus a runtime load check for a namespaced class extending \ArrayObject, ClassProxyGenerator cases for the global parent and global introductions, and a ClassGenerator alias case. No existing snapshot changed. Closes #759 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KXjD75egSqDNujmNS5kr5c
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #762 +/- ##
=========================================
Coverage 97.63% 97.64%
- Complexity 1829 1830 +1
=========================================
Files 104 104
Lines 4829 4831 +2
=========================================
+ Hits 4715 4717 +2
Misses 114 114 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
What and why
Fixes #759.
The bug: a woven class in a namespace that extends a global class, for example
class Coll extends \ArrayObjectinnamespace Bug2, gotextends ArrayObjectin its proxy. That resolved toBug2\ArrayObject, and including the proxy failed withError: Class "Bug2\ArrayObject" not found.The change:
ClassProxyGeneratorroots the parent class name it takes from reflection:'\\' . $parentClass->getName(). This mirrors what was already done for the original interfaces.rootClassName()helper. Callers that skipAdviceMatcher(which already roots them) are now safe too.ClassGenerator::addTraitAlias()keeps the trait name as given instead of stripping the leading\. Before, an aliased global trait was written asGlobalTrait::min the alias line, which resolved inside the proxy's namespace.ClassGenerator::classNameNode()keeps its semantics (only its docblock is extended). TheFooOriginalTraitreference keeps its deliberate short relative name, and the shortusealiases for framework and aspect classes are unchanged.src/Proxy/AGENTS.md.Verification
The repro from #759 (
Bug2\Coll extends \ArrayObjectwith an advisedhello(), empty cache):Fatal error: Uncaught Error: Class "Bug2\ArrayObject" not found[advice] collclass Coll extends ArrayObject implements \IteratorAggregate, …class Coll extends \ArrayObject implements \IteratorAggregate, …Tests
global-parent-class.php(Test\ns1\GlobalParentCollection extends \ArrayObject implements \Countable) with woven and proxy snapshots.WeavingTransformerTest::testWeaverRootsGlobalParentClassOfNamespacedClasscompares against them and asserts the proxy compiles.testWovenClassWithGlobalParentClassWorksAtRuntimeincludes the woven trait and proxy from vfs, then checksis_subclass_of(\ArrayObject), instantiation and item access.ClassProxyGeneratorTest:extends \ArrayObject, while the OriginalTraitusestays short;\.ClassGeneratorTest: the alias of an explicitly rooted global trait stays fully qualified.src/Proxyis touched, so the transformation performance group does not apply.No CHANGELOG entry: the bug comes from the trait-based engine of the unreleased 4.0.
Checklist
type(scope): summary)composer checkpasses🤖 Generated with Claude Code
https://claude.ai/code/session_01KXjD75egSqDNujmNS5kr5c
Generated by Claude Code