Skip to content

fix(php): resolve member calls in remapped files and through inherited methods, keep every call site - #5364

Closed
livingforelvis wants to merge 2 commits into
Graphify-Labs:v8from
livingforelvis:fix/php-member-calls
Closed

livingforelvis wants to merge 2 commits into
Graphify-Labs:v8from
livingforelvis:fix/php-member-calls

Conversation

@livingforelvis

@livingforelvis livingforelvis commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

  • Fixes [Bug]: PHP member calls dropped in remapped files, through inherited methods, and on repeat call sites #5362: _resolve_php_member_calls dropped PHP calls whose target is plain from the source
  • Remapped extensions: the resolver gated on the literal .php suffix; it now gates on _lang_family, like the extractor registry, so language.inc=php files get Cls::m() / self::m() / parent::m() edges
  • $this->m() resolves against the enclosing class, exact like self::
  • Every scope looks the method up the inherits chain level by level: nearest class that provides it wins, a tie on that level binds nothing (the Java resolver's rule)
  • On each class, PHP precedence: its own method, then a used trait's (through traits that use traits), then the parent's
  • Repeat call sites: extract_php passes preserve_call_sites=True and the resolver dedups per (caller, target, line), so a second call reaches the build and folds into also_seen ([Feature]: don't erase weaker-confidence evidence when edges or paths merge #4881)
  • _merge_decl_def_classes keys a calls edge by its file and line too, so its corpus-wide dedup removes only the twins a header/definition merge creates, never a repeat call (it ran on the whole corpus once one .h/.cc member merged, so it dropped PHP repeat calls in mixed corpora)
  • _AST_CACHE_SCHEMA 49 -> 50, so cached PHP extractions re-run

Type of change

  • Bug fix

Verification & Invariants

  • Invariant: one calls edge per PHP call site the resolver can bind; the build folds repeats of one pair into also_seen

  • Invariant: a method is bound only when exactly one class on the nearest providing level of the inherits chain provides it

  • $this::m() (dynamic scope) and untyped instance receivers stay unresolved, as before

  • Limitation: interfaces are not walked (no method body); insteadof/as trait conflict rules are not read, so two traits providing one method bind nothing

  • Limitation: $this-> / static:: bind the enclosing class's view, not a subclass override (late binding), same as self::

  • Not changed: C++ repeat call sites still collapse earlier, in the cross-file call resolver

  • Cache schema bump: feat(java): dispatch interface method calls to their implementers (#5319) #5323 also moves 49 -> 50; whichever lands second takes 51

  • Read the CONTRIBUTING.md guide.

  • Reproduced the issue and identified the invariant.

  • Made the smallest fix necessary.

  • Added a regression test.

  • Kept the PR description synchronized with the final implementation.

  • Documented any limitations / unsupported cases explicitly.

How was this tested?

  • New tests/test_php_member_call_gaps.py:
    • .inc corpus with language.inc=php: Cls::m(), self::m(), parent::m() resolve EXTRACTED
    • inherited $this->m() binds the parent's method, with a same-named decoy class
    • two-hop parent::m() binds the grandparent's method
    • nearest declaring class wins over a grandparent
    • no declaring class in the chain: no edge
    • two bases on one level declaring the method: no edge
    • a used trait's method beats the parent's; the class's own beats the trait's; a trait used by a trait is found
    • an inherits cycle ends with no edge; a non-PHP member call is skipped; $this::m() stays unresolved
    • repeat call keeps both lines, with and without a .h/.cc member merge in the corpus
    • build_from_json carries the second line in also_seen
    • the header merge still removes its own duplicate contains/method edges
code under test uv run pytest tests/test_php_member_call_gaps.py -q
origin/v8 (f51d46c) 10 failed, 6 passed
this branch 16 passed

Failing on v8:

FAILED tests/test_php_member_call_gaps.py::test_static_calls_resolve_in_a_file_mapped_to_php
FAILED tests/test_php_member_call_gaps.py::test_this_call_to_an_inherited_method_binds_the_parent_method
FAILED tests/test_php_member_call_gaps.py::test_parent_call_two_levels_up_binds_the_grandparent_method
FAILED tests/test_php_member_call_gaps.py::test_nearest_declaring_class_wins
FAILED tests/test_php_member_call_gaps.py::test_a_trait_method_wins_over_the_inherited_one
FAILED tests/test_php_member_call_gaps.py::test_a_method_from_a_trait_used_by_a_trait_is_found
FAILED tests/test_php_member_call_gaps.py::test_a_member_call_outside_php_is_left_alone
FAILED tests/test_php_member_call_gaps.py::test_a_repeat_call_keeps_both_lines[php-only]
FAILED tests/test_php_member_call_gaps.py::test_a_repeat_call_keeps_both_lines[with-cpp-header-merge]
FAILED tests/test_php_member_call_gaps.py::test_the_build_folds_the_repeat_call_into_also_seen

Repro from #5362 (three .inc files, language.inc=php), calls edges from extract():

v8 this branch
.run() -> .helper() L4 ($this->, two levels up) missing present
.run() -> .helper() L5 (repeat) missing present
.boot() -> .setup() L8 (parent::, two levels up) missing present
.make() -> .setup() L9 (self::, inherited) missing present
  • uv run --with pytest-xdist pytest tests -n 8 (first commit) — 8 failed, 11619 passed, 165 skipped, 1 xfailed; the 8 (test_terraform_modules parallel cases, test_language_override_lifecycle[modify], test_workers_by_work_size::test_extract_honours_env) pass serially: 84 passed
  • After the trait commit, -k "php or cpp or decl_def or also_seen or cache or merge or trait" — 6 failed, 1396 passed; the 6 are the same test_terraform_modules parallel cases, serially 13 passed
  • Trait repro (class C extends P { use T; }, both declare m): .run() -> .m() bound to P.php before, T.php after
  • uv run ruff check on changed files — All checks passed!
  • uv run pyright graphify/extract.py graphify/extractors/resolution.py — 192 errors, the same 192 as on v8

Graphify-specific checklist

  • No skill artifact sources changed
  • AST/structural extraction stays deterministic
  • No unsafe interpolation into shell/Python
  • No API keys or local-only graph data included

…d methods, keep every call site

- Gate _resolve_php_member_calls on _lang_family, so a .graphifyrc-mapped extension (language.inc=php) is resolved
- Bind $this->m() to the enclosing class, like self::
- Look the method up the inherits chain level by level: nearest declaring class wins, a tie binds nothing
- Keep one edge per call site in the PHP extractor and resolver, so repeats reach also_seen (Graphify-Labs#4881)
- _merge_decl_def_classes keys calls edges by call site, so its dedup keeps repeat call sites
- _AST_CACHE_SCHEMA 49 -> 50

Refs Graphify-Labs#5362
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @livingforelvis. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.11 and 3.13, and that the change keeps extraction deterministic.

@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Nov 20, 2026
@livingforelvis
livingforelvis marked this pull request as ready for review November 20, 2026 22:05

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify code review View in Graphify

Review finished · 85a59790597b

Warning

Merge confidence: 4/5 · Review before merging · 🟠 High impact
1 P2 bug checked against the code · 4 possible issues not confirmed

Bugs (1)

P2 · Filter inaccessible private methods in declared_from: child $this->secret() and parent::secret() calls can otherwise emit calls edges to a parent method PHP does not allow them to access. Inspect source

Detailed review · checked against the code

Child calls can link to an inaccessible private parent method

A child’s $this->secret() or parent::secret() can be recorded as calling a parent’s private method, even though PHP does not allow that call from the child.

Expected: The graph should not link the call to a method PHP makes inaccessible from the child.
Actually: The resolver can select the parent’s private method by name and emit a calls edge to it.

The resolver indexes method edges by owner and name without filtering visibility, and declared_from walks the inheritance chain until it finds a match. For $this->secret(), the new special case selects the caller’s class and the inherited lookup can then return the parent’s private method; for parent::secret(), the resolver selects the parent and can return that private method directly. It emits a calls edge for either match. PHP does not allow a child to call a parent’s private method through either form, so these edges misrepresent the source. The resolver is registered and run for PHP files through the language resolver registry.

  • Independent source review: Checked the inherited-call tests: they cover public parent methods, trait precedence, and lookup ties, but do not check private methods. No visibility check appears in the inspected lookup or call-emission path. The base implementation already directly looked up methods on the parent:: receiver, so that form could link a private parent method before this change; the new inherited lookup adds the same false link for $this->secret() when the child has no matching declaration.

Not confirmed (4 possible issues)

Leads worth a look; we didn't double-check these. They don't change the score.

Not confirmed · Each test extraction leaves a new temporary cache directory behind in the system temp folder Inspect source

Detailed review · not confirmed

The _extract helper passes a fresh tempfile.mkdtemp() directory as cache_root on every call, and nothing removes it, so each test run leaves more directories behind.

Line 38 calls extract(paths, cache_root=Path(tempfile.mkdtemp()), root=tmp_path, parallel=False). mkdtemp creates a directory that persists after the test finishes, and no finally, addfinalizer, or fixture cleans it up. The test already receives pytest's tmp_path fixture, which is cleaned up automatically, so the cache could live under it instead.

  • Whether extract scans or caches anything under root when cache_root sits inside tmp_path was not checked, since the extract source is not in this review.

  • Only this test file was reviewed; the behavior of extract with cache_root is unverified.

  • Found by the per-file sweep; not double-checked.

Not confirmed · static:: calls are bound to the calling method's own class, so a subclass override is never the resolved target Inspect source

Detailed review · not confirmed

The self/static branch resolves static:: to the class where the caller is defined, but PHP late static binding dispatches static:: to the class actually called at runtime.

At line 7836 both self and static take the same path, type_nid = enclosing_type.get(caller), so static is treated exactly like self. The new docstring at lines 7727-7728 calls self::/static:: exact because the keyword names the class unambiguously, but static:: does not name a fixed class.

  • The subclass that actually receives the call is not visible from the call site, so the resolver cannot tell whether an override exists.

  • Found by the per-file sweep; not double-checked.

Not confirmed · Chosen definition location is compared as text, so L10 can sort before L9 and the reported definition may not be the earliest one Inspect source

Detailed review · not confirmed

The tie-break that picks which implementation file's location becomes definition_location compares source_location as a string. A location like L10 sorts before L9, so the recorded definition site may not be the lowest line the comment promises.

Lines 4162-4163 build the sort key as (str(source_file), str(source_location)). Strings sort lexicographically, so "L10" < "L9". The comment at 4154-4156 says the choice is 'lowest source_file, then location', which only holds if the location is compared numerically. The sort is still deterministic, so the failure is an incorrect choice rather than nondeterminism. The exact format of source_location is not visible in this hunk, so this depends on whether it contains unpadded numbers.

  • The format of source_location values is not shown in this hunk; the problem only occurs if they hold unpadded line numbers.

  • Whether the header node already carries a definition_location from an earlier pass is not visible here.

  • Found by the per-file sweep; not double-checked.

Not confirmed · Repeated calls edges that differ only by source file are no longer merged, so duplicate edges created by the collapse can survive Inspect source

Detailed review · not confirmed

The de-duplication key for calls edges now includes source_file and source_location. Edges that were copied during the merge from a duplicate node may carry a different source file and therefore are no longer recognised as duplicates.

Lines 4193-4196 extend the key k with (source_file, source_location) for calls edges so that real repeat call sites are kept for also_seen. The comment at 4182-4183 says the de-dup step exists to remove edges that become identical after the collapse. A merge copy with a different source_file now has a different key, so it is kept. Whether the merge actually produces such copies is not visible in this hunk.

  • Not shown whether merged duplicate calls edges can carry a different source_file from their original.

  • The consumer of also_seen is outside this hunk, so its expectations for duplicate call edges are unverified.

  • Found by the per-file sweep; not double-checked.

What this review covered
  • This review stopped before it finished; findings are from the part that ran.
  • The AI model asked for code in a way the review could not use.
  • 4 of 4 changed files inspected. This is scope, not a correctness guarantee.
Code graph and static checks · 5829 functions depend on this change

Impact & health

Impact — 5829 functions depend on the 744 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: _resolve_php_member_calls() — 2 callers, 6 callees

Formal checks — 5829 functions this change can affect weren't formally checked in this review. Formal checks are informational only.

Health delta baseline: last indexed commit dfab9cc (diverged from this PR's base — delta is approximate).

Gate & verification

✅ PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 5256 function(s) in the blast radius were not formally verified this run

Test selection

390 of 602 test file(s) selected (65%) via static blast radius.

  • tests/test_4874_jvm_resolution.py — impact
  • tests/test_4909_reference_binding_scale.py — impact
  • tests/test_4978_reconcile_cost.py — impact
  • tests/test_4992_ts_import_types.py — impact
  • tests/test_affected_overrides.py — impact
  • tests/test_alias_folding.py — impact
  • tests/test_analyze.py — impact
  • tests/test_astro_extraction.py — impact
  • tests/test_astro_import_ids.py — impact
  • tests/test_binary_media_words.py — impact
  • tests/test_blade_extractor.py — impact
  • tests/test_build.py — impact
  • tests/test_build_located_semantic_identity.py — impact
  • tests/test_build_merge_dedup_scope.py — impact
  • tests/test_build_merge_ghost_fold_4955.py — impact
  • tests/test_build_merge_hyperedges_and_prune.py — impact
  • tests/test_build_merge_shrink_guard.py — impact
  • tests/test_builtin_global_type_refs.py — impact
  • tests/test_c_include_resolution.py — impact
  • tests/test_cache.py — impact
  • tests/test_cache_long_paths.py — impact
  • tests/test_cache_stale_import_target.py — impact
  • tests/test_cache_windows_case_4925.py — impact
  • tests/test_carried_hyperedge_remap.py — impact
  • tests/test_case_only_decl_ids_4904.py — impact
  • tests/test_case_sensitive_resolution.py — impact
  • tests/test_charmap_encoding.py — impact
  • tests/test_chunking.py — impact
  • tests/test_cjs_module_extension.py — impact
  • tests/test_cli_export.py — impact
  • tests/test_cluster.py — impact
  • tests/test_cobol_extractor.py — impact
  • tests/test_code_only_scope_4923.py — impact
  • tests/test_confidence.py — impact
  • tests/test_confidence_score_output.py — impact
  • tests/test_corrupt_graph_json.py — impact
  • tests/test_cpp_alias_member_resolution.py — impact
  • tests/test_cpp_anonymous_namespace_receivers.py — impact
  • tests/test_cpp_conditional_initializers.py — impact
  • tests/test_cpp_forward_declarations.py — impact
  • tests/test_cpp_forward_receiver_completion.py — impact
  • tests/test_cpp_inherited_member_resolution.py — impact
  • tests/test_cpp_local_callable_shadowing.py — impact
  • tests/test_cpp_member_call_by_receiver_type.py — impact
  • tests/test_cpp_member_declaration_identity.py — impact
  • tests/test_cpp_method_declarations.py — impact
  • tests/test_cpp_nested_and_cli.py — impact
  • tests/test_cpp_objc_cross_file_calls.py — impact
  • tests/test_cpp_receiver_chains.py — impact
  • tests/test_cpp_receiver_parameters.py — impact
  • … and 340 more

Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.

Every flagged function

  • _resolve_php_member_calls() in graphify/extract.py:7708 · 2 callers, 6 callees: fans out to 6 callees (efferent coupling)

safishamsi added a commit that referenced this pull request Nov 21, 2026
…batch

Fold the Rust (#5380), C# (#5376) and PHP (#5362) AST-output changes into
the unreleased _AST_CACHE_SCHEMA = 51 entry (alongside the GHSA-g6c9-j4vm-mwq4
bash change already there), so cached Rust/C#/PHP extractions re-run on the
next build. Document the #5229 Python import-binding limitation (plain-module
re-exports are left unresolved rather than chased) in ARCHITECTURE.md, and add
the 0.9.115 changelog entries for the batch.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Landed in v0.9.115 via an authorship-preserving cherry-pick (both commits). Member calls now resolve in remapped files (e.g. .inc via .graphifyrc) and through the inherits/trait chain (nearest level wins, ties fail closed), and every call site is kept (the build folds repeats into also_seen). Maintainer tweaks on merge: rebased onto current v8 and folded the schema note into the combined unreleased 51. Thanks @livingforelvis!

@safishamsi safishamsi closed this Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: PHP member calls dropped in remapped files, through inherited methods, and on repeat call sites

2 participants