Several woven classes in one file: their proxies overwrite each other, all but the last class are lost (Class not found)
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 38/100
Research direction
Start in WeavingTransformer::saveProxyToCache() in src/Instrument/Transformer/WeavingTransformer.php (around lines 974-993), where the proxy path is built from the source file alone, and in the include lines the woven source gets. Read the snapshot tests multiple-classes-woven.php and multiple-ns.php under tests/Instrument/Transformer/_files/, then bump CachePathManager::FORMAT_VERSION if the layout changes. Done means one combined proxy file per source file, with every woven class in its own namespace, plus a test that actually loads all the classes.
Written by the indexing model from the issue text.
Description
Problem
When one source file declares several classes that are woven, every proxy is written to the same cache file. The last proxy wins, and the other classes are never defined at runtime.
Reproduce (master 4e95fdd)
// app/Two.php
namespace Bug1;
class First { public function hello(): string { return 'first'; } }
class Second { public function hello(): string { return 'second'; } }
The aspect is #[Before('execution(public Bug1\**->hello(*))')]. The kernel uses appDir = app/.
After the file is included through the loader:
class_exists('Bug1\Second', false)→true;(new Second())->hello()runs the advice.class_exists('Bug1\First', false)→false;new First()fails withError: Class "Bug1\First" not found.trait_exists('Bug1\FirstOriginalTrait', false)→true. The trait is woven, but its proxy class is gone.cache/Two.php(the proxy file) contains onlyclass Second.
Cause
WeavingTransformer::saveProxyToCache()(src/Instrument/Transformer/WeavingTransformer.php:974-993) builds the proxy path from the source file path only:{cacheDir}/{relative source path}. Each woven class of the file overwrites the previous proxy.- The woven source then contains one
include_once AOP_CACHE_DIR . '/…/Two.php';per class, all for the same path. The first one loads the last written proxy, and the later ones do nothing.
The existing snapshot tests/Instrument/Transformer/_files/multiple-classes-woven.php already encodes this: three classes share the identical include_once AOP_CACHE_DIR . '/Transformer/_files/multiple-classes.php'. The test never loads the classes, so it passes.
Expected / decided direction
Keep one proxy file per source file: put all proxies of the file together in that single cache file, not one file per class.
- The woven source includes that file once, after all
…OriginalTraitdeclarations it needs are defined. - The runtime class map (
_include.cache) maps every woven class of the file to the same cached file. - Namespaces: a source file may declare classes in several namespaces (see
multiple-ns.php). The combined proxy file has to keep every proxy in its own namespace, with its own imports, for example as braced namespace blocks.
Acceptance
- The snapshot tests for
multiple-classesandmultiple-nsare updated, and a test actually loads all classes of such a file (unit or functional). - Classes in the same file that are not woven stay as they are.
- Single-class files produce byte-identical output to master, or any difference is explained.
- If the cache layout or format changes, bump
CachePathManager::FORMAT_VERSION.
- 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
-
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
-
Bug Known Issue
Difficulty 4/5 3-5 days Newbie friendliness 30/100
goaop/framework#696 · 1 comment ·
Maintainers usually reply within 1 day
Similar issues
-
sync-en
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
sync-en
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 4 days
-
Перевод устарел
Difficulty 1/5 Under an hour Newbie friendliness 85/100
-
bug
Difficulty 2/5 Half a day Newbie friendliness 76/100
m3ue/m3u-editor#1604 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
femiwiki/docker-mediawiki#1497 ·
Maintainers usually reply within 1 day