[PHP] include/require(_once) not mapped to dependency edges — only namespace `use`; impact/callers miss the file-include graph
What happened
On a procedural / script-style PHP codebase (the kind that organizes code with include/require rather than Composer/PSR-4 namespaces — plenty of legacy apps, plain-PHP sites, and older CMS themes still look like this), codegraph builds an excellent call graph but produces zero file→file dependency edges for include / require / include_once / require_once.
Concretely: a page file foo.php whose first line is include("../loader.php"); yields callers(loader.php) = 0 and no edge of any kind linking foo.php → loader.php. The same holds for require_once. Only namespace use statements become import/dependency edges.
The call graph itself is great here — callers/callees/impact correctly attribute top-level (file-scope) function calls to the file node, which is exactly right for procedural code. This report is only about the missing include/require dependency layer.
Why it matters
For namespaced codebases this is a non-issue: use covers the dependency graph. But for include-based PHP, the include statement is the dependency mechanism — it's how a file gains access to the functions/constants it calls. Without those edges:
impact/callerscan't answer "if I changehelpers.php, which files thatincludeit (directly or transitively) are affected?" beyond the direct function-call edges.- The file-level architecture graph is missing its primary structural relationship for this style of code.
Root cause (source)
src/extraction/languages/php.ts:
importTypes: ['namespace_use_declaration'],
importTypes lists only namespace_use_declaration. The PHP tree-sitter grammar represents includes as include_expression, require_expression (and the _once variants), which appear in none of the captured node-type lists (importTypes, callTypes, variableTypes, …), and visitNode only special-cases const_declaration and trait use_declaration. So include/require nodes are simply never visited as dependency edges.
Suggested fix
Capture include_expression / require_expression (+ _once variants) and emit a file→file dependency/import edge, resolving the argument string to a path (relative to the including file / configured roots). Even resolving only static string literals (the common case) would cover the overwhelming majority of real include sites; dynamic includes (include $var) can be skipped.
Repro
- Two files in the same dir:
lib.php:<?php function greet() { return "hi"; }page.php:<?php require_once("lib.php"); echo greet();
- Index the directory.
callers lib.php→ returns 0 (no include edge frompage.php).callees page.php→ shows thegreetcall edge, but no dependency edge tolib.php.
Environment
- codegraph
@colbymchenry/[email protected](vianpx -y) - Node v24.2.0
- Windows 11 (x64)
Verified on a real ~650-file procedural PHP project: the call graph matched grep ground truth at 100% file-level coverage for a representative helper, while every include/require relationship was absent from the graph.
Picking this up.
Confirmed root cause in `src/extraction/languages/php.ts`: `importTypes` only captures `namespace_use_declaration`, and `include`/`require`(`_once`) expressions appear in none of the captured node-type lists, so they never become dependency edges.
Plan: capture the include/require expressions and emit file→file `imports` edges by reusing the existing path-based resolution that C/C++ #include already goes through in `resolveViaImport` (resolving static string-literal paths; dynamic `include $var` skipped, as you noted). PR incoming.
Fixed by #663 (merged to main) — thanks @maxmilian for the clean implementation, and @atahan150 for the precise report and root-cause analysis.
include / require / include_once / require_once of a static path now emit a file→file dependency edge, so codegraph_callers and codegraph_impact follow includes in procedural/script-style PHP — not just namespace use. The implementation mirrors how C/C++ #include already resolves: it distinguishes an include path (lib.php, inc/db.php, ../x.php) from a namespace use symbol (App\Foo\Bar, Closure) by shape, resolves the path relative to the including file, and — importantly — creates no edge when the path doesn't resolve to a known project file, rather than mis-connecting to a same-named file elsewhere. Dynamic forms (include $var, require __DIR__ . '/x', interpolated strings) are skipped, as you both suggested.
Verified against your repro (page.php require_once("lib.php") → callers(lib.php) now includes page.php), subdirectory includes, the dynamic-skip cases, and a mis-resolution safety case. Full suite green.
Ships in the next release; re-index to pick up the new edges.