Skip to content

Partial reflection: reflect a class whose ancestors are not available instead of throwing #251

Closed

Description

@lisachenko

Problem

To reflect a class, the engine has to locate every ancestor: parent class, interfaces and traits. It reflects an ancestor natively only when it is already declared; otherwise it asks the locator. When the locator can't find it, reflection throws:

InvalidArgumentException: Class GeneratedCode\Admin\BaseReportController was not found by locator

The ancestor may be generated at runtime and loaded by another autoloader, declared by class_alias(), or defined outside the Composer autoloader. The whole class then can't be reflected, even for questions that don't need the missing ancestor: its own methods, properties, attributes, or whether its name matches a pattern.

For goaop/framework this means a class below the include paths fails to weave. It fails even when the pointcut can't match any of its methods, because matching walks every method, including inherited ones (found while working on goaop/goaop-symfony-bundle#17).

Feature: partial reflection

When an ancestor can't be located, return a partial reflection instead of throwing:

  • What comes from the class's own source stays available: name, modifiers, own methods, properties, constants and attributes, and the names of the parent, interfaces and traits as written.
  • Information that needs the missing ancestor (inherited members, getParentClass(), isSubclassOf(), prototypes) is either omitted or reported explicitly.
  • The reflection says it is partial, e.g. isPartial(): bool plus the list of missing class names, so the caller decides what to do.

The application chooses the policy:

  • strict (default, current behaviour): throw as today;
  • partial: return partial reflection. A consumer such as goaop/framework can then weave with what is known (for example the class's own methods), skip the class with a clear message, or stop.

A switch on ReflectionEngine::init() or the locator would let existing users keep the current behaviour.

Activity

  1. added a commit that references this issue on Nov 2, 2026
    ea89dd2
  2. lisachenko commented on Nov 5, 2026

    @lisachenko
    MemberAuthor

    Implemented and released in 4.2.0 / 5.2.0:

    goaop/framework uses this through the opt-in Features::PARTIAL_REFLECTION flag (goaop/framework#788).


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions