Skip to content

Resolve a self-typed parameter to its declaring class - #160

Merged
rasuvaeff merged 1 commit into
masterfrom
fix/self-parameter-type
Oct 14, 2026
Merged

rasuvaeff merged 1 commit into
masterfrom
fix/self-parameter-type

Conversation

@rasuvaeff

Copy link
Copy Markdown
Owner

Fixes #158

What

  • A parameter typed self was written through into the generated override, where self names the generated subclass. PHP 8.3/8.4 rejected the signature as narrowed. It now renders as the declaring class, the way parent already did (TypeRenderer::resolveSelf()); returns keep the keyword, where a subclass is a legal narrowing.
  • A method that comes from a trait was affected on PHP 8.5 too: Reflection leaves a trait's self unresolved on every version. The declaring class Reflection reports for it is the using class, which is what self means there.
  • Found along the way: qualify() compared relative keywords case-sensitively, so SELF / Parent / STATIC rendered as \SELF — a fatal on 8.3/8.4 in both parameter and return position.

Tests

  • Fixtures in tests/Fixture/Unify/: class (self, ?self), interface, trait + user.
  • TargetUnifierEdgeTest: end-to-end doubles for each shape, rendered type carries no self.
  • TypeRendererTest: unit cases, plus an uppercase SELF declared via eval inside a trait (the only place 8.5 keeps the keyword literal, so the case is exercised on every version).

Verification

  • Unit suite on php:8.3-cli and php:8.4-cli: 1182 passed.
  • composer build + composer rector (8.5): green.
  • make mutation-diff: 17 mutants, 0 escaped, covered MSI 100%.
  • Without the fix the suite dies with exit 255 — on 8.3 at the self case, on 8.5 at the trait case.

A generated override wrote `self` through, and inside the generated class
that names the generated subclass, so PHP 8.3/8.4 rejected the signature as
narrowed. A trait method was affected on 8.5 too. The keyword check in
qualify() was also case-sensitive, so `SELF` rendered as `\SELF`.

Fixes #158
@coderabbitai

coderabbitai Bot commented Oct 14, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d9f84439-8f45-46ae-87e5-443eb404e60d
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@rasuvaeff
rasuvaeff merged commit 6ed023f into master Oct 14, 2026
24 checks passed
@rasuvaeff rasuvaeff mentioned this pull request Oct 14, 2026
@rasuvaeff
rasuvaeff deleted the fix/self-parameter-type branch October 17, 2026 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A self-typed parameter makes a class double a fatal on PHP 8.3 and 8.4

1 participant