Skip to content

PHP: instance ($g->m()) member calls produce no edge across files, and nothing across repos #3390

Closed

Description

@xiongjianxu

Net-new over v8 (verified against current v8 tip)

#3872 taught the PHP resolver to bind scoped calls — Class::method(),
self::, static::, parent:: — to the actual method. Two gaps remain:

1. Instance calls stay unresolved

A call on a typed receiver is still dropped:

// Greeter.php
class Greeter { public function greet(): void {} }

// App.php
class App {
    private Greeter $greeter;
    public function run(): void { $this->greeter->greet(); }   // no edge
}

$this->greeter->greet() / $g->greet() resolve to nothing — v8 routes a
$var receiver to its "dynamic scope" branch and gives up. The receiver's class
is written down (property, promoted ctor param, typed param, or new), so the
edge is recoverable. This is the PHP twin of the Swift gap in #1356.

2. Nothing crosses a repo boundary

Even once the receiver is typed, a class this build does not contain cannot be
resolved, and php is absent from cross_repo_calls._LANG_SUFFIXES, so the
parked entry (#3152) is never language-checked and the merge drops it.

Scope

Resolution is by the receiver's declared type with the single-definition guard,
gated to the PHP interop family. An untyped, union, longer-chain or ambiguous
receiver produces no edge. The scoped :: path from #3872 is unchanged.

PR: #3391

Activity

  1. xiongjianxu commented on Sep 22, 2026

    @xiongjianxu
    ContributorAuthor

    Self-contained, runnable reproduction (driven only by graphify on PYTHONPATH, so the same script runs against pristine v8 and against the PR branch). Two single-file repos are built — app calls a method on a type declared only in lib — then merge-graphs is run; the parked entry and the cross-repo calls edge are printed.

    # repro_php.py  —  python repro_php.py   (exit 0 = fixed, 1 = bug present)
    import json, subprocess, sys, tempfile
    from pathlib import Path
    from graphify.extract import extract
    
    FILES = {
        "app/App.php": '<?php\nclass App {\n    private Greeter $greeter;\n    public function run(): void { $this->greeter->greet(); }\n}\n',
        "lib/Greeter.php": '<?php\nclass Greeter {\n    public function greet(): void {}\n}\n',
    }
    
    def _extract(root):
        files = sorted(f for e in ("*.php", "*.ts", "*.kt", "*.m", "*.h")
                       for f in root.rglob(e))
        return extract(files, cache_root=root / "graphify-out")
    
    def _write(p, res):
        p.parent.mkdir(parents=True, exist_ok=True)
        p.write_text(json.dumps({"directed": False, "multigraph": False, "graph": {},
                                 "nodes": res["nodes"], "links": res["edges"]}))
    
    def main():
        with tempfile.TemporaryDirectory() as d:
            tmp = Path(d)
            for rel, body in FILES.items():
                p = tmp / rel
                p.parent.mkdir(parents=True, exist_ok=True)
                p.write_text(body)
            ag = tmp / "app/graphify-out/graph.json"
            bg = tmp / "lib/graphify-out/graph.json"
            _write(ag, _extract(tmp / "app"))
            _write(bg, _extract(tmp / "lib"))
            parked = [e for n in json.loads(ag.read_text())["nodes"]
                      if isinstance(n.get("metadata"), dict)
                      for e in n["metadata"].get("unresolved_calls", [])]
            print("parked:", parked or "(none)")
            out = tmp / "merged.json"
            subprocess.run([sys.executable, "-m", "graphify", "merge-graphs",
                            str(ag), str(bg), "--out", str(out)], cwd=tmp, check=True)
            xr = [e for e in json.loads(out.read_text())["links"]
                  if e.get("relation") == "calls" and e.get("context") == "cross_repo"]
            print("cross_repo calls:",
                  [(e["source"], e["target"]) for e in xr] or "(none)")
            return 0 if xr else 1
    
    sys.exit(main())

    On pristine v8 (20a20d3):

    parked: (none)
    cross_repo calls: (none)          # exit 1
    

    The receiver's type is declared only in the other repo, so nothing is parked and merge-graphs has nothing to finish — the call edge is lost across the boundary, exactly as described.

    With PR #3391:

    parked: [{"callee": "greet", "receiver_type": "Greeter", "lang": "php", "line": "L4"}]
    cross_repo calls: [('app::…app_run', 'lib::…greeter_greet')]   # exit 0
    

    The call is parked by name (no node ids, per the #3152 contract) and finished by link_cross_repo_member_calls as an INFERRED / context=cross_repo edge when the type resolves to exactly one declaration in another repo.

    PR #3391 cherry-picks clean onto the current v8 tip 20a20d3 (git merge-tree reports no conflicts; PR is MERGEABLE / CLEAN).

  2. changed the title [-]PHP: member calls on a typed receiver produce no edge across files, and nothing across repos[/-] [+]PHP: instance (`$g->m()`) member calls produce no edge across files, and nothing across repos[/+] on Oct 13, 2026
  3. xiongjianxu commented on Oct 13, 2026

    @xiongjianxu
    ContributorAuthor

    Resolved in 0.9.89. Both halves landed on v8: single-build instance resolution ($g->m() through the receiver's declared type, INFERRED) in commit 0d635ff, and cross-repo linking of the parked call in commit d045891 — credited in the 0.9.89 release notes. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions