Skip to content

fix(php): a receiver reaches the class PHP means, through its real parents and traits - #3168

Merged
colbymchenry merged 1 commit into
mainfrom
claude/fx-php-class-ancestry
Nov 1, 2026
Merged

colbymchenry merged 1 commit into
mainfrom
claude/fx-php-class-ancestry

Conversation

@colbymchenry

Copy link
Copy Markdown
Owner

Summary

Regression items 1, 2 and 6 of REG (PHP): $entity->access() no longer lands on the views HandlerBase, and a Laravel receiver reaches the override, not the base. A PHP class is now found the way PHP finds one, for what a variable named after it reaches and for a declared type.

Root cause

  • Bisected to e043efb (fix(resolution): bind Class.method() to the class itself, not a class whose name contains it #1935): classStrategyMethod took what a class inherits, walked by bare supertype names, for any class named after the receiver. 1.6.2 took only a method in the class's own file.
  • So $entity reached the views plugin Entity in a namespace the file never mentions, three classes below HandlerBase; Comments extends Collection asked every Collection; a trait was never asked.
  • A typed receiver found nothing when the method sat on a supertype, since the first pass has no extends edges, and went on to the same guess.
  • phpSupertypeQns read the five lines at a declaration's start, which on an attribute-heavy class (#[ContentEntityType(…)]) hold no extends. Past such a "parent outside the repository", parent::x() was allowed any trait of the project.

Fix

  • A class comes through the file's namespace and use imports, group imports included; its parents through the imports of the file declaring it, past its attributes, with a trait before the parent.
  • A receiver named after a class the file names reaches all it inherits. One the file can't name gives its own method, or what it inherits when it is the one class of that name.
  • A declared type answers through that ancestry in the first pass, and its receiver's name leads to no class. A namesake's method is asked only past a parent outside the project or a __call (Laravel's Eloquent Builder).
  • A Laravel facade hands a static call to the class getFacadeAccessor() names (::class only). A local an Eloquent model's static factory gives is that model.
  • parent::x() above a parent from outside the project is no trait of the project.

Validation

Red to green: 9 of 16 tests in php-receiver-class-ancestry.test.ts fail on main; the other 7 guard the rules beside them.

A/B against 4499d00, all CLI steps rc 0:

Repo Edges Moved Added Lost
framework 974cd809 169,744 to 171,080 3,209 1,398 62
drupal-core (REG's sparse copy) 38,099 to 39,053 381 1,066 112
bookstack 045c6a98 80,019 to 80,026 6 7 0
koel da0e70f4 70,636 to 70,666 53 30 0
ospos, ci3, invoiceplane, horizon byte-identical
controls gin, flask byte-identical

Classes, 125 sampled entries read against source, 0 false added:

  • Moved: typed receivers onto the class their file imports. Top groups on framework: 271 $v->fails() from the Validator contract to the new Validator, 201 UrlGenerator, 142 event dispatch off Bus\Dispatcher, 62 Factory::fake off the Http factory onto Process's. Traits: 178 make on EnumeratesValues, 32 pluck on Eloquent\Collection.
  • Added: typed calls on supertypes ($entity->id() on EntityInterface), and 834 on drupal-core of $this->x() and parent::x() in classes whose attributes hid their parents.
  • Lost, framework: 48 parent::__construct above Exception that reached an unrelated trait; 7 that were true only through a namesake the file can't name ($user->getKey(), $post->incrementEach() with $post from tap(…)).
  • Lost, drupal-core: 353 moved or gone from traits a call never reaches (BlockPluginTrait::__construct), and the HandlerBase class.
  • HandlerBase: 52 of 62 edges gone. 9 of the 10 left are $url->access(), because core/lib/Drupal/Core/Url.php is outside the sparse clone; with that one file back all 18 *url*.access reach Url::access. One is $view->access() inside class View, which nothing tells from an instance of it.
  • Worth knowing: 19 user.getAuthIdentifier-style edges on a $user the file can't name go back to 1.6.2's GenericUser from Authenticatable: the receiver is a test user or a contract there, so neither is the class that runs.

REG's PUB entries: all 7 on framework and all 9 on drupal-core now hold, and framework/lost/4 comes back as the facade forward it really is.

Index CPU on framework, median of 5 interleaved: 47.9 to 48.1 s (+0.5%); wall 13.1 to 13.5 s. No extraction change, so no kernel parity.

Suite on the top of this stack, 6e22039, on main 3bd9949: 857 files passed, 6 skipped; 10,662 tests passed, 0 failed, 87 skipped (kernel built, 4 workers). A rebuild after the rebase gave the same graphs as the A/B build on sinatra, serilog, eShopOnWeb, drupal-core and bookstack.

Stacked: this is the base of the Ruby, C# and JS PRs.

🤖 Generated with Claude Code

…rents and traits

Since #1935 a receiver named after a class took what that class inherits,
walked by bare supertype names. Drupal's `$entity->access()` went to the
views plugin `Entity`, in a namespace the calling file never mentions, and
up three classes to `HandlerBase::access`; Laravel's `$comments->pluck()`
took `Support\Collection::pluck` past the `Eloquent\Collection` the class
imports, and `$pivot->getForeignKey()` took `Model`'s past its trait
`AsPivot`. A typed receiver whose method sat on a supertype found nothing in
the first pass, since no `extends` edge exists yet, and went on to the same
guess.

A class is now found the way PHP finds one: through the calling file's
namespace and `use` imports (group imports included), its parents through
the imports of the file declaring it, past any attributes above it, a
trait before the parent.
- A receiver named after a class the file names reaches all it inherits,
  and that class comes before its namesakes. One the file can't name gives
  only its own method, or what it inherits when it is the one class of that
  name: a word picks no namesake.
- A declared type answers through its source ancestry in the first pass.
  Its name no longer leads to a class named after the variable, and a
  namesake's method is asked only past a parent outside the project or a
  `__call`.
- A Laravel facade hands a static call to the class `getFacadeAccessor()`
  names. A local an Eloquent model's static factory gives is that model.
- `parent::x()` above a parent from outside the project is no trait of the
  project.

Validation, base 4499d00 against this change, every class read and a sample
of each against source (numbers in the PR):
- framework 974cd809: 169,744 to 171,080 edges, 3,209 moved, 1,398 added, 62 lost.
  Moved: typed receivers onto the class their file names (271 `$v->fails()`
  from the Validator contract to the `new Validator`, 142 event dispatches off
  `Bus\Dispatcher`), traits (`make`, `pluck`). 48 of the 62 lost are
  `parent::__construct` above Exception reaching an unrelated trait; 7 were true
  only through a namesake (`$user->getKey()` on a `User` the file can't name).
- drupal-core (REG's sparse copy, no .git): 38,099 to 39,053, 381 moved, 1,066
  added, 112 lost. 52 `HandlerBase` edges go. 10 are left: 9 `$url->access()`
  on the one `Url` left when core/lib/Drupal/Core/Url.php is outside the sparse
  checkout (with that file back they reach `Url::access`), and a `$view->access()`
  inside `class View` itself. 834 `parent::` and
  `$this->` calls link through classes with attributes above them; 353 calls off
  unrelated traits (`BlockPluginTrait::__construct`) move or go.
- bookstack 045c6a98: 6 moved, 7 added. koel da0e70f4: 53 moved, 30 added.
- ospos, ci3, invoiceplane, horizon, controls gin and flask: byte-identical.
- Read against source: 125 sampled entries, 0 false added. Index CPU on framework,
  median of 5 interleaved: 47.9 to 48.1 s (+0.5%).
- REG: all 16 PUB entries for framework and drupal-core now hold.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant