Proxy of a namespaced class extending a global class references the parent unqualified (Class "Ns\ArrayObject" not found)
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 62/100
Research direction
Start with ClassGenerator::classNameNode() in src/Proxy/Generator/ClassGenerator.php, which only emits a fully qualified name when there is a leading backslash or a namespace separator, then trace the parent name passed from src/Proxy/ClassProxyGenerator.php around line 187. Reproduce with a namespaced class extending \ArrayObject and check that the generated proxy loads. Done when the extends clause and trait names are always fully qualified and the fixture and snapshot tests pass.
Written by the indexing model from the issue text.
Description
Problem
A woven class in a namespace that extends a class from the global namespace gets a proxy whose extends clause names the parent unqualified. The name then resolves inside the proxy's namespace, and including the proxy fails. This affects any extends \Exception, \RuntimeException, \ArrayObject, \DateTimeImmutable, and so on.
Reproduce (master 4e95fdd)
// app/Coll.php
namespace Bug2;
class Coll extends \ArrayObject implements \Countable
{
public function hello(): string { return 'coll'; }
}
The aspect is #[Before('execution(public Bug2\**->hello(*))')]. The kernel uses appDir = app/; debug mode makes no difference.
Generated proxy (cache/Coll.php):
namespace Bug2;
// …
class Coll extends ArrayObject implements \IteratorAggregate, \Traversable, \ArrayAccess, \Serializable, \Countable, \Go\Aop\Proxy
Result: Error: Class "Bug2\ArrayObject" not found in cache/Coll.php:9 when the woven file includes the proxy.
Cause
src/Proxy/ClassProxyGenerator.php:187passes$parentClass->getName()(ArrayObject, with no leading\) toClassGenerator.ClassGenerator::classNameNode()(src/Proxy/Generator/ClassGenerator.php:127-134) only emitsName\FullyQualifiedwhen the name has a leading\or contains a namespace separator. A global class name therefore becomes a relativeName.- Interfaces are not affected, because they are prefixed with
\explicitly (ClassProxyGenerator.php:180). - Used traits (
ClassGenerator.php:176,184) go through the sameclassNameNode(), so a trait declared in the global namespace is probably affected the same way.
Expected
extends \ArrayObject. Reflection always returns fully qualified names, so the parent (and the trait names) should always be emitted fully qualified. This also applies to the enum and trait proxy generators, if they pass reflection names through the same helper.
Acceptance
- Weaving fixture and snapshot test: a namespaced class extending a global class (
\ArrayObjector\Exception), and a class using a trait from the global namespace. - A functional or compile check that the generated proxy loads.
- Generated code stays clean: the short-alias rules from AGENTS.md apply. A global name written as
\ArrayObjectis fine.
- Dominant language
- PHP
- Stars
- 1.7k
- Forks
- 166
- Avg merge
- 11h 20m
- Merged PRs (30d)
- 37
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from goaop/framework
-
Intercepting a method imported from a trait with #[\Override] fails: OriginalAlias "has #[\Override] attribute, but no matching parent method exists"Possibly taken @lisachenko claimed this 1 day ago. OpenBug PHP8.4
Difficulty 3/5 Half a day Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
Several woven classes in one file: their proxies overwrite each other, all but the last class are lost (Class not found)Possibly taken @lisachenko claimed this 1 day ago. OpenBug
Difficulty 4/5 3-5 days Newbie friendliness 38/100
Maintainers usually reply within 1 day
-
Enhancement Performance
Difficulty 5/5 Over a week Newbie friendliness 35/100
goaop/framework#747 · 1 comment ·
Maintainers usually reply within 1 day
-
Enhancement Performance To Be Discussed
Difficulty 3/5 Half a day Newbie friendliness 55/100
Maintainers usually reply within 1 day
-
Feature
Difficulty 4/5 3-5 days Newbie friendliness 45/100
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
components-web-app/api-components-bundle#403 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
mollie/PrestaShop#1566 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
components-web-app/docs#193 ·
-
docs: add Python and PHP examples to docs/api.mdPossibly taken @gaurika-analyst claimed this today. Opendocumentation good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
djazairdev/wilayas#12 · 1 comment ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
endoflife-date/endoflife.date#11314 ·
Maintainers usually reply within 1 day