Repository navigation
Description
Problem
Measured during 0.9.34 release verification (probe scenario "10 use-alias outside corpus (Risk 6)") and filed as #16: a PHP property typed via a use alias whose target is outside the corpus, combined with exactly one unrelated in-corpus class of the same short name, mints a wrong INFERRED 0.8 calls edge.
Minimal repro (two files; the false edge is App\Http\I::go -> App\Local\Client::send INFERRED 0.8):
// app/Local/Client.php
<?php
namespace App\Local;
class Client { public function send(): int { return 1; } }// app/Http/I.php
<?php
namespace App\Http;
use Vendor\Sdk\Client;
class I {
private Client $c;
public function go(): int { return $this->c->send(); }
}Root cause: _resolve_php_member_calls binds a short receiver-type name through a corpus-wide short-name index (type_def_nids, extract.py:3166-3173) whose only refusal rule is "more than one candidate" (extract.py:3247-3260). The use alias makes Client a claimed name that should be decisive, but the resolver never sees use statements. Compounding: _php_name_text (engine.py:671-675) flattens every written type to its short name, so even a fully-qualified \Vendor\Sdk\Client annotation is indistinguishable from a bare Client.
This was accepted as out of scope by spec #1 and documented in the 0.9.34 changelog; this spec is the documented upgrade path: use-import-map awareness following the C# CsharpNameResolver pattern.
Prior art: the C# mechanism (v8 @ 102ae79)
- Capture —
_import_csharp(extract.py:577-605): everyusingdirective becomes animportsedge that preservestarget_fqn,alias,using_kind, and lexical scope (scope_kind/scope_id). - Storage —
CsharpNameResolver.__init__(graphify/extractors/csharp.py:174-222) rebuilds per-file using/alias maps from those edges (no re-parse) plus a(namespace, simple_name) -> node_idindex from nodemetadata.namespace. - Consult —
resolve_type_name(csharp.py:269-296) returns a(node_id, decisive)verdict. The trick is decisive-on-miss: an alias to an out-of-corpus type returns(None, True), and the caller (extract.py:2870-2885) then refuses instead of falling back to the corpus-wide bare-name index. That refusal is exactly what PHP is missing.
Existing PHP infrastructure to reuse
- A correct
use-parser already exists:_resolve_php_type_references(graphify/extractors/resolution.py:2417-2648) buildsuses_by_filevia_record_use_clause(resolution.py:2476-2495) and thenamespace_use_declarationwalk (:2504-2517). It already handles group useuse A\{B, C};, aliasesuse X as Y;, aliased group use, and rejectsuse function/use const. But its maps are function-local and it only repointsinherits/implements/mixes_in/imports/references— nothing survives for the member-call pass. - The lossy counterpart is
_import_php(extract.py:664-681):raw.split("\\")[-1], emitsimportsedges with no metadata at all. - Namespace facts exist twice:
_php_pre_scan_class_namespaces(engine.py:183-237, per-fileshort -> FQN, feeds inline-newcorroboration only) and the re-parse inresolution.py. Two different multi-namespace-file policies (per-declaration vs bail-entirely). - Incremental-rebuild carry-over precedent (commits
8d051c6,85bb8df): persisted underscore markers on the file node (engine.py:5262-5290), preserved ingraph.json(extract.py:6171-6176), read back inwatch.py:1205-1225/cli.py:3140-3160, re-injected via_php_context_interface_entry(extract.py:3106-3136, wired at:6019-6034).
Design decisions (resolved; flagged for maintainer review)
- Reuse the
resolution.pyuse-parser — do not write a second one. Extract_record_use_clause+ thenamespace_use_declarationwalk into a shared helper consumed by both_resolve_php_type_referencesand the new capture path. A fresh bare-loop parser in_import_phpwould mishandle group use and function/const imports (the current code mishandles groups entirely). - Stay on the per-file-payload + persisted-marker channel; do not add
metadata.namespaceto PHP nodes. Matches the PHP interface refusal does not survive incremental rebuilds, minting a wrong edge (user stories 10 + 19) #11/PHP: enum- and trait-typed receivers bypass the interface refusal and bind an unrelated same-short-named class #12/PHP: EXTRACTED corroboration matches the file path only, ignoring the declared namespace #14 precedent already wired through watch/cli/context-injection, and avoids changing the node shape every PHP pass sees. Flagged alternative: true C# parity viametadata.namespacewould benefit every future PHP pass but has a much wider blast radius — revisit if a third consumer of PHP namespace facts appears. - Incremental-parity contract: refusal may land alone; positive binding must ship with the carry-over marker. The
usemap belongs to the calling file (always freshly dispatched), so the decisive refusal (PHP use-import map 3/5: PhpNameResolver decisive refusal (closes #16) #21) is correct on both full and incremental runs without new markers. The positive alias binding (PHP use-import map 4/5: positive alias binding via namespace index #22) needs the declared FQNs of unchanged defining files, so PHP use-import map 5/5: incremental-rebuild parity marker for declared FQNs #23 (the marker) must land in the same release as PHP use-import map 4/5: positive alias binding via namespace index #22 — otherwise incremental rebuilds silently lose the edges PHP use-import map 4/5: positive alias binding via namespace index #22 adds, the exact PHP interface refusal does not survive incremental rebuilds, minting a wrong edge (user stories 10 + 19) #11-parity failure mode.
Convention note: keep the resolution.py casefold convention for names; PHP namespace segments are case-insensitive.
Tickets
- Capture — enrich PHP
importsedges withtarget_fqn/alias/use_kindmetadata via the shared parser (mirror_import_csharp). No behavior change; metadata-shape tests only. Independently landable. - Qualified receiver types — thread the written qualified name alongside the short name for property/param/promoted-param/local type positions (
engine.py:671-675,:717-740,:761-885; today only inline-newkeepsreceiver_qualified,engine.py:4903). On its own this lets a fully-qualified annotation resolve or refuse correctly. Widest-blast-radius ticket: it changes the receiver-type table's value shape. PhpNameResolverdecisive refusal — closes PHP: use-alias pointing outside the corpus + one same-short-named in-corpus class mints a wrong INFERRED edge (design risk 6, measured) #16. New resolver mirroringcsharp.py:174-296returning(nid, decisive), consulted in_resolve_php_member_calls(extract.py:3247-3260) in front of thetype_def_nidsfallback, exactly like the C# call site (extract.py:2870-2885). Strictly subtractive: an alias-claimed short name that doesn't resolve in-corpus refuses instead of falling back. Depends on 1 (+2 for FQ-annotation coverage).- Positive alias binding — use the alias to bind
use App\Services\X;to the rightXamong several same-short-named in-corpus classes, via a(namespace, name)index sourced from thephp_class_fqnspayload (engine.py:5285-5290). Additive-only recall win. Depends on 3. - Incremental parity — persist the declared-FQN marker for unchanged defining files and wire the four established carry-over sites; mirrored incremental tests per the
test_php_member_calls.py:1544-1878pattern (_full_then_incremental). Must ship with 4.
Risk profiles: 3 can only delete edges; 4 can only add or re-point them. Review them separately.
Risks / traps (from triage)
- Group use and aliased group use are already right in
resolution.py:2508-2517— reuse beats rewrite. use function/use constmust not enter the class-name map (resolution.py:2479-2480).- Trait
useinside a class body is a different AST node (use_declaration);_PHP_CONFIG.import_typesisfrozenset({"namespace_use_clause"})(extract.py:926) — do not widen tonamespace_use_declarationor trait mixins become imports. - Multi-namespace files: two existing policies disagree (
resolution.py:2541-2542bails;engine.py:183-237is per-declaration). Pick per-declaration and note it. _resolve_php_type_referencesruns atextract.py:5594-5606, member-call resolvers at:6030— shared state must be valid at both points or built twice.- No test in
tests/test_php_member_calls.pycovers this scenario today (grepVendorreturns nothing); the only repro lives in/tmp— the fixture above is the canonical copy.
References
- Bug: PHP: use-alias pointing outside the corpus + one same-short-named in-corpus class mints a wrong INFERRED edge (design risk 6, measured) #16 · Parent spec: PHP: resolve instance-method calls edges from typed receivers (upstream Graphify-Labs#1682) #1 (out-of-scope item) · Upstream: PHP: member/instance method calls never resolve to calls edges — only static Class::method() works Graphify-Labs/graphify#1682
- C# pattern:
graphify/extractors/csharp.py:174-296,extract.py:577-605,:2870-2885 - Carry-over precedent: commits
8d051c6,85bb8df
Activity
filipechagas commentedon Aug 6, 2026
All five tickets have landed on v8, closing the spec:
useFQN/alias/kind metadata onimportsedges (PR feat(php): capture use FQN/alias/kind metadata on imports edges (#19) #29)PhpNameResolver, closed PHP: use-alias pointing outside the corpus + one same-short-named in-corpus class mints a wrong INFERRED edge (design risk 6, measured) #16 (PR fix(php): refuse a member call whose receiver type the file claims (#21, closes #16) #32)_php_class_fqnsmarker through the four carry-over sites (PR feat(php): positive alias binding via declared FQNs + incremental parity marker (#22, #23) #35)#22 and #23 shipped together in one release per design decision 3. Verification for the final pair (PR #35): full suite 4124 green on merged v8; differential extract vs
v8@cec9cddover a 25-file shape corpus — 6 edges added (allApp\Alpha\X::send, INFERRED 0.8), 0 deleted, 0 re-pointed; end-to-endgraphify extract→ touch callers →graphify updatereproduces all edges with the defining files undispatched, and a pre-marker graph fails closed.Upstreaming status: Graphify-Labs#2492 (base feature) and Graphify-Labs#2502 (#19) are open upstream; #20–#23 stack on them and go upstream once those merge.
filipechagas commentedon Aug 6, 2026
Spec delivered in full on v8.