Repository navigation
Description
Upstream issue: Graphify-Labs#1682 (confirmed present at v8 HEAD, 0.9.33, via a live repro build).
Problem Statement
When a user points an AI coding assistant at a graphify graph of a PHP codebase and asks "what depends on this service / what breaks if I change it", the answer is silently wrong. calls edges exist only for static calls (ClassName::method()). Instance-method calls — constructor-injected dependencies ($this->service->method()), typed locals, and inline instantiation ((new Service())->method()) — produce no calls edge at all, even when the callee class is statically knowable. Constructor injection is the dominant call pattern in modern Laravel code, so for most service classes the inbound-calls answer is empty. Worse, the graph looks complete (rich inherits/method/contains edges), so the user has no signal that the most useful edge type for impact analysis is missing.
Solution
The PHP extractor learns to read the receiver of an instance call, and a new PHP language resolver turns receiver + declared type into a calls edge — but only when the answer is unambiguous. The resolver follows the existing Java member-call resolver's philosophy: resolve when the receiver has exactly one known concrete type, that type has exactly one definition in the corpus, and that definition has exactly one matching method; otherwise refuse and emit nothing. Type-inferred edges carry the INFERRED confidence label; inline-new edges, where the source names the exact class, carry EXTRACTED. Static-call behavior is unchanged. Remaining limitations are stated in the changelog so the edge set no longer looks complete when it is not.
User Stories
- As an AI assistant user, I want
get_neighbors("LeadHunterService")to return the controllers that call it through constructor-injected properties, so that impact analysis matches reality. - As an AI assistant user, I want
(new \App\Services\MixedPaymentService())->resolve()call sites to appear as inboundcallsedges onMixedPaymentService, so that inline-instantiated services are not invisible. - As an AI assistant user, I want calls through typed locals (
$svc = new LeadHunterService(); $svc->search()) to producecallsedges, so that local-variable dispatch is tracked. - As an AI assistant user, I want calls through natively typed properties (
private Mailer $mailer) to producecallsedges, so that property-injected dependencies are tracked. - As an AI assistant user, I want calls through typed method parameters (
function handle(LeadHunterService $svc)) to producecallsedges, so that method-injected dependencies are tracked. - As an AI assistant user, I want nullable-typed receivers (
?Mailer) to resolve to the underlying class, so that the common nullable-dependency idiom is not a blind spot. - As an AI assistant user, I want nullsafe calls (
$this->mailer?->send()) to resolve the same way as regular member calls, so that modern PHP 8 syntax is covered. - As an AI assistant user, I want static
Class::method()edges to keep working exactly as today, so that the fix does not regress the one pattern that already works. - As an AI assistant user, I want same-file
$this->method()calls to keep producing edges as today, so that existing intra-class call graphs are preserved. - As a graph consumer, I want no
callsedge when the receiver's type is an interface, so that the graph never guesses which implementation is bound. - As a graph consumer, I want no
callsedge when the receiver is untyped, union-typed, or intersection-typed, so that common method names (log(),find(),execute()) never produce false cross-class edges. - As a graph consumer, I want no
callsedge when a local variable is reassigned or rebound (including by a closure parameter or aforeachtarget that shadows it), so that scope confusion never produces a wrong edge. - As a graph consumer, I want no
callsedge when two classes in the corpus share the receiver's type name, so that ambiguity is refused rather than resolved by luck. - As a graph consumer, I want no
callsedge when the resolved class has no matching method, so that magic-method dispatch (Eloquent) is never guessed. - As a graph consumer, I want chained receivers (
$a->b()->c()) left unresolved, so that return-type inference is never faked. - As a graph consumer, I want type-inferred edges labelled
INFERREDand inline-newedges labelledEXTRACTED, so that I can weigh edges by how directly the source states them. - As a graph consumer, I want an interface sharing a short name with an unrelated class to block resolution, so that Laravel's Contracts naming convention does not mint edges into the wrong class.
- As a user of mixed-language corpora, I want PHP receiver data to never leak into the Swift, Python, or TypeScript member-call resolvers, so that a PHP variable name cannot mint an edge into another language's class.
- As a user of
graphify update(watch/incremental), I want the new resolution to run on incremental rebuilds too, so that the graph does not drift after edits. - As an upgrading user, I want stale cached extraction data invalidated on release, so that pre-fix caches cannot produce receiver-less results.
- As a maintainer, I want the changelog to state exactly which member calls now resolve and which are deliberately refused, so that users can calibrate trust in the edge set.
- As a maintainer, I want the new resolver to follow the existing Java resolver's structure and guard set, so that the codebase keeps one recognizable pattern for typed-receiver resolution.
Implementation Decisions
-
Receiver capture (extraction): the shared tree-sitter engine's PHP member-call walk records a receiver key alongside the method name. The mapping, verified by AST probes against the pinned tree-sitter-php grammar (prototype output):
Source form Receiver key Extra $this->m()this$this->prop->m()this.prop$var->m()var(new X())->m(),(new \NS\X())->m()(new)class name, plus the qualified text when the source gives one anything else (chains, array access, $$var, anonymous classes)none — behavior unchanged -
Nullsafe member calls are added to the PHP call node types; they share the regular member-call shape.
-
Type tables: a per-class map from property name to declared type is built from typed property declarations and constructor-promoted parameters — the two sites the engine already parses for
referencesedges. A per-method layer adds natively typed parameters and locals assigned withnew. Binding conflicts poison the name (Java convention), and poisoning explicitly covers: reassignment to a non-newvalue, conflictingnewtypes, closure and arrow-function parameters,foreachtargets, and list-destructuring elements. Anonymous-class subtrees are skipped when walking method bodies. -
Concrete-type policy: a type contributes to the table only when it is a single named class type. Nullable unwraps to its inner type. Union, intersection, primitive,
self,static, andparenttypes are refused — including when they appear as the class of anewexpression. Docblock types are ignored. -
Raw-call stamping: the resolved receiver type and a PHP language tag are stamped on the raw call record (the C#/Java pattern). The existing in-file bare-name match is skipped only when a receiver type was actually stamped — untyped receivers keep today's same-file edges.
-
Resolution pass: a new PHP member-call resolver, registered through the language-resolver registry (so it runs in both full and incremental builds automatically), structured as a clone of the Java member-call resolver. Receiver
thisresolves against the caller's enclosing class. Otherwise the pass requires a stamped receiver type, exactly one definition of that type in the corpus, and exactly one matching method on it — any failed condition means no edge, with no bare-name fallback. Name matching is case-insensitive (PHP semantics, consistent with the shared pass). -
Interface refusal: PHP interface declarations do not mint class definition nodes today, which would let a lone same-short-named class silently satisfy the single-definition guard. The extractor therefore pre-scans interface names (following the existing C# interface pre-scan pattern), and the resolver refuses any receiver type whose name matches a known interface.
-
Confidence: type-inferred edges are
INFERRED(score 0.8). Inline-newedges areEXTRACTED(score 1.0) only when the source's qualified name corroborates the resolved node; otherwise they are downgraded toINFERRED. -
Cross-resolver hardening: the Swift, Python, and TypeScript member-call resolvers gain a language-tag skip so that language-tagged raw calls (PHP, and incidentally the pre-existing ObjC leak) can no longer flow through them in mixed corpora. The Ruby resolver needs no change — it already filters by file suffix.
-
Cache and release: the package version is bumped so the version-namespaced AST cache invalidates raw calls that predate the new receiver fields.
-
Transparency: the changelog entry names both what now resolves and what is deliberately refused; the how-it-works doc gains a note in its confidence section.
Testing Decisions
- Seam: every test goes through the public
extract()pipeline entry point — fixture files in a temp directory in,{nodes, edges}out. Tests assert only external behavior: the presence or absence of specificcallsedges and their confidence labels. No internal helper (receiver-table builder, concrete-type helper) is tested directly; their behavior is fully observable at the seam. - Good-test shape: every positive case includes a decoy class defining an identically named method, and asserts the decoy received no edge — a resolution test that cannot catch mis-binding proves nothing.
- Prior art:
test_java_member_calls.py(structure, decoy corpus,extract()usage),test_csharp_member_calls.py(confidence and negative-assertion idioms),test_php_type_resolution.py(PHP fixture style). - New test module covering, as
extract()-level cases: the three upstream repro scenarios (constructor-promoted property →INFERRED; inlinenew→EXTRACTED; static control unchanged); typed local, typed property, typed parameter, nullable, and nullsafe positives; the same-file$this->method()preservation case; and negatives for every refusal guard — untyped, union, reassigned local (both non-newrebind and conflictingnew), closure/foreachshadowing, duplicate class names, interface-typed receiver, interface/class short-name collision, unknown method with no fallback edge, and chained receivers. - One mixed-corpus test (.php + .py in a single
extract()call) proving PHP receiver data cannot mint an edge through the Python resolver. - Regression suites to run unchanged: the existing PHP language tests, PHP type-resolution tests, and the C#, Java, TypeScript, and ObjC member-call suites (the ObjC suite guards the incidental leak closure).
Out of Scope
- Resolving interface-typed receivers to implementations, including via
use-import maps or Laravel service-containerbound_toedges. This is the documented upgrade path, not this change. - Methods provided by traits or inherited from parent classes (the method index does not walk inheritance; Java parity).
- Docblock-only types (
@var), chained-call receivers, and array-element receivers. - Bare
new X()statements without an immediate method call (unchanged from today). - The residual wrong-edge exposure where a
usealias points outside the corpus while one unrelated in-corpus class shares the short name — accepted and documented; the Java resolver has the identical exposure today.
Further Notes
- One known behavior delta: a same-file call through a receiver that is now concretely typed moves from the bare-name
EXTRACTEDedge to the resolver'sINFERREDedge (same endpoints, different label). The existing PHP language test still passes; the PR description must state the delta. - Pre-merge checks that remain open from design verification: run the full test suite (the design was verified against source line-by-line, but tests were not executed in the review environment); probe the older tree-sitter-php versions the project accepts, or raise the version floor; one-line AST probes for anonymous classes and
self/staticin type position; one manual incremental-rebuild test across the version-bump cache boundary. - Provenance: this spec was produced from an 11-agent investigation of the upstream issue — 7 investigators (including a live repro at HEAD and tree-sitter AST probes), 1 designer, and 3 adversarial verifiers whose corrections (interface short-name bypass, closure/foreach scope poisoning, defer-only-when-typed, inline-new FQN corroboration, Ruby hardening refuted) are folded into the decisions above.
Activity
filipechagas commentedon Aug 5, 2026
Submitted upstream as Graphify-Labs#2492 (head lawnstarter:feat/php-member-calls-1682, db7c8f8, 0.9.34). All child tickets #2-#7 closed, plus review-phase fixes #8/#11/#12/#13/#14. Known-open residuals tracked: #9, #10, #15, #16. Leaving this spec open until the upstream PR merges.
Merge pull request #17 from lawnstarter/feat/php-member-calls-1682