Repository navigation
fix(php): a receiver reaches the class PHP means, through its real parents and traits - #3168
Merged
Merged
Conversation
…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>
bompus
added a commit
to bompus/codegraph
that referenced
this pull request
Nov 2, 2026
…rents and traits (colbymchenry#3168) Ported from upstream 14c25e3
This was referenced Nov 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Regression items 1, 2 and 6 of REG (PHP):
$entity->access()no longer lands on the viewsHandlerBase, 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
classStrategyMethodtook 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.$entityreached the views pluginEntityin a namespace the file never mentions, three classes belowHandlerBase;Comments extends Collectionasked everyCollection; a trait was never asked.extendsedges, and went on to the same guess.phpSupertypeQnsread the five lines at a declaration's start, which on an attribute-heavy class (#[ContentEntityType(…)]) hold noextends. Past such a "parent outside the repository",parent::x()was allowed any trait of the project.Fix
useimports, group imports included; its parents through the imports of the file declaring it, past its attributes, with a trait before the parent.__call(Laravel's EloquentBuilder).getFacadeAccessor()names (::classonly). 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.tsfail on main; the other 7 guard the rules beside them.A/B against 4499d00, all CLI steps rc 0:
Classes, 125 sampled entries read against source, 0 false added:
$v->fails()from theValidatorcontract to thenew Validator, 201UrlGenerator, 142 eventdispatchoffBus\Dispatcher, 62Factory::fakeoff the Http factory onto Process's. Traits: 178makeonEnumeratesValues, 32pluckonEloquent\Collection.$entity->id()onEntityInterface), and 834 on drupal-core of$this->x()andparent::x()in classes whose attributes hid their parents.parent::__constructaboveExceptionthat reached an unrelated trait; 7 that were true only through a namesake the file can't name ($user->getKey(),$post->incrementEach()with$postfromtap(…)).BlockPluginTrait::__construct), and theHandlerBaseclass.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*.accessreachUrl::access. One is$view->access()insideclass View, which nothing tells from an instance of it.user.getAuthIdentifier-style edges on a$userthe file can't name go back to 1.6.2'sGenericUserfromAuthenticatable: 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/4comes 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