Skip to content

Name missing ancestors of a partial reflection as written in the source - #254

Merged
lisachenko merged 4 commits into
4.xfrom
feature/friendly-cori-zyci9y
Nov 3, 2026
Merged

lisachenko merged 4 commits into
4.xfrom
feature/friendly-cori-zyci9y

Conversation

@lisachenko

@lisachenko lisachenko commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #251 / #252, needed by goaop/framework#788 (review: the framework must not read parser-reflection's AST to recover the names of missing ancestors).

Problem

A partial reflection (MissingAncestorPolicy::Partial) left a missing parent class, interfaces and traits out of every API, even though their names are known from the source. A consumer that needs those names, such as the framework's proxy generator re-declaring extends/implements, had to resolve them from getNode() itself.

Change

  • New ReflectionClass::getParentClassName(): string|false (also on ReflectionEnum, through the trait): returns the name of the parent class as written in the source, located or not, without reflecting it. It returns false when the class declares no parent. getParentClass() now uses it too.
  • For a partial reflection:
    • getInterfaceNames() includes the missing interfaces declared by the class and by its available ancestors (for example, a missing interface of the parent class is named through the parent). implementsInterface() agrees with it.
    • getTraitNames() includes the missing traits the class uses.
    • getInterfaces() and getTraits() still list only the ancestors that were located.
  • A complete (non-partial) reflection is unaffected: these methods take the same path as before.
  • One private instance method of the trait, getAncestorNamesFromSource(), reads the parent class, interfaces and traits from $this->classLikeNode. getParentClassName(), getInterfaceNames(), getTraitNames() and getMissingClassNames() all use it, and nothing new is added to the public static API.
  • ReflectionClass::collectMissingAncestorNames(), added in 4.1 and hardly used yet, is removed: getMissingClassNames() of the reflection replaces it.

This changes behaviour released in 4.1 / 5.1: a partial reflection's getInterfaceNames() and getTraitNames() used to leave missing ancestors out. #251 asked for "the names of the parent, interfaces and traits as written" to stay available, so this aligns with the issue.

Tests

  • PartialReflectionTest:
    • getParentClassName() returns the missing parent, a located parent and false, under both policies;
    • getInterfaceNames() / implementsInterface() / getTraitNames() include the missing ancestors for the class, for a child of a partial class and for an interface extending a missing one, while getInterfaces() / getTraits() still list only the located ones.
  • vendor/bin/phpunit: 13,765 tests pass. Skipped and incomplete counts are unchanged.

Docs

The README's partial reflection section, docs/reflection_class.md and CLAUDE.md are updated.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FxhC1CBg4rnTu9UjAMcCpL

A partial reflection left a missing parent class and missing interfaces out
of every API, so a consumer that needs their names (a proxy generator
re-declaring extends/implements, for instance) had to read them from the AST
node itself.

- ReflectionClass::getParentClassName() returns the name of the parent class
  as written in the source, located or not, without reflecting it;
- getInterfaceNames() and implementsInterface() of a partial reflection
  include the missing interfaces declared by the class and by its available
  ancestors. getInterfaces() still lists the located ones only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FxhC1CBg4rnTu9UjAMcCpL
Comment thread src/ReflectionClass.php Resolved
Comment thread src/ReflectionClass.php Resolved
Comment thread src/Traits/ReflectionClassLikeTrait.php Resolved
Review feedback: the declared names of the parent class and interfaces were
read by static ReflectionClass::getDeclaredParentName() and
getDeclaredInterfaceNames(), next to getParentClassName() and
getInterfaceNames() doing the same job.

- the static helpers are removed; one private instance method of the trait,
  getAncestorNamesFromSource(), reads the parent class, interfaces and traits
  from $this->classLikeNode, and getParentClassName(), getParentClass(),
  getInterfaceNames(), getTraitNames() and getMissingClassNames() use it;
- getTraitNames() of a partial reflection names the missing traits too, like
  getInterfaceNames() does for interfaces;
- ReflectionClass::collectMissingAncestorNames(), released in 4.1, is kept as
  a deprecated wrapper of getMissingClassNames().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FxhC1CBg4rnTu9UjAMcCpL
PHPStan does not apply a docblock above a closure assignment to its
parameters, so the name nodes were mixed: check them with instanceof.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FxhC1CBg4rnTu9UjAMcCpL
Comment thread src/ReflectionClass.php Resolved
It was added in 4.1 and is hardly used yet: getMissingClassNames() of the
reflection replaces it, no deprecated wrapper is kept (review feedback).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FxhC1CBg4rnTu9UjAMcCpL
@lisachenko
lisachenko marked this pull request as ready for review November 3, 2026 16:56
@lisachenko
lisachenko merged commit b208742 into 4.x Nov 3, 2026
7 checks passed
@lisachenko
lisachenko deleted the feature/friendly-cori-zyci9y branch November 3, 2026 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants