You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ReflectionParameter loads the class of a new default value with include_once while it is constructed #261
Creating a Go\ParserReflection\ReflectionParameter whose default value is a new expression (Collaborator $helper = new Collaborator('x')) resolves the default eagerly, and NodeExpressionResolver::resolveExprNew() loads the class with include_once of its source file (loadClassDefinition()).
Two effects:
Reflecting a signature has a side effect: it declares a class, and it does so although nobody asked for the default value.
The include_once bypasses the autoloader. In goaop/framework the class is therefore declared from its original source while another class is being woven, and can not be woven any more in that process: its advices (for example an initialization(...) advice) silently do not apply.
Affected versions
Reproduced with 5.2.0 on PHP 8.5.12, through goaop/framework 4.x (0450cdf).
Expected: true, as when VA::run() has no such default, or as in production mode after cache:warmup:aop (verified: there Collaborator is woven, because weaving happened in another process).
The same new in a static variable initializer, in an attribute argument or as the default of a promoted constructor parameter of a method that is not intercepted does not trigger it; only the parameters of an intercepted method are reflected by the proxy generator.
Possible fix
Resolve the default value lazily, on getDefaultValue(), instead of in the constructor of ReflectionParameter; the framework only needs the parameter names, types and the default's AST there.
When a new expression has to be evaluated, load the class through the autoloader (class_exists($name)), not with include_once of the located file, so that a class loader hooked into Composer still sees the load.
Related
Found while verifying the entries of docs/php85-limitations.md in goaop/framework (goaop/framework#603 is the neighbouring, fixed, problem). #259 is another resolver problem found the same day.
Activity
build: require goaop/parser-reflection ^4.2.1 || ^5.2.1