Skip to content

fix(php): statement-anchored, one-line _dependency_capture (#3609) - #3634

Merged
squid-protocol merged 1 commit into
mainfrom
claude/festive-fermat-kojuy7
Sep 25, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
claude/festive-fermat-kojuy7

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Closes #3609.

Problem

PHP's _dependency_capture started a capture at any require, include or use word. There was a \b before the keyword but none after it, and the capture ran to the next ;, across lines. So all of these became "imports":

  • included, includes/x.php, $required;
  • 'require_once' used as an array key;
  • $this->aliasInclude(...);
  • id="required" in inline HTML;
  • English prose inside strings.

wordpress/functions.php carried 56 of these, including a whole table of HTTP status strings (403 => 'Forbidden'). The alternation also tried include before include_once, so include_once ABSPATH . 'x.php' was captured as _once ABSPATH . 'x.php'.

Fix

  • A keyword starts a capture only as a whole word in statement position:
    • line start;
    • after ; { } = ( , @ & | ) (so if (...) require ... still counts);
    • after return, else, echo, print or <?php.
  • require and include take their _once suffix.
  • The statement must stay on one line. The expression is bounded, the trailing blanks are bounded, and the expression can't start with a blank. ReDoS tests cover long blank runs and long unterminated lines.
  • use imports keep their multi-line group form (use A\{B, C};).

Verification

  • import_graph_accuracy php (guzzle): precision 99.0% → 99.2%, recall 100%. Baseline regenerated. The 3 remaining false edges are the resolver mapping GuzzleHttp\Psr7\Utils to guzzle's own src/Utils.php; that isn't a capture problem.
  • Golden masters (both modes): the only changes are PHP Extracted Dependencies, the matching Direct Upstream Fragility, firewall imports_unknown 10501 → 10290, and the Composition Fit ripple.
    • 13 files change: 231 junk tokens are gone.
    • The real includes are now read correctly: the _once-prefixed ones lose their prefix, and 3 require_once $plugin-style variables are newly captured.
    • Every removal was checked against the source: $path/$alias came from aliasInclude($path, $alias), and none of the changed files contains another include statement. No use import changed.
  • Tests: new statement-anchor and ReDoS tests in tests/extraction/languages/test_php.py; the php tests pass.
  • Other gates:
    • tree_sitter_accuracy_audit --lang php --ci: OK.
    • call_graph_accuracy --ci: OK.
    • ruff and dead-key audits: no new findings.

🤖 Generated with Claude Code

https://claude.ai/code/session_01YAtpBfGGyBGGovitSVaM5Q


Generated by Claude Code

The capture started at any `require`/`include`/`use` word (bare `\b`, no
closing boundary) and ran to the next `;` across lines, so `included`,
`includes/x.php`, `'require_once'` array keys, `$required`,
`->aliasInclude(`, `d="required"` in inline HTML and English in strings all
became "imports" -- wordpress/functions.php carried 56 of them, including a
table of HTTP status strings. And `include` was tried before `include_once`,
so `include_once ABSPATH . 'x.php'` captured `_once ABSPATH . 'x.php'`.

A keyword now starts a capture only as a whole word in statement position
(line start, after `; { } = ( , @ & | )`, `return`, `else`, `echo`, `print`
or `<?php`); `require`/`include` take their `_once` suffix; the statement
stays on one line with a bounded expression and bounded trailing blanks
(ReDoS-tested). `use` imports keep their multi-line group form.

import_graph_accuracy php (guzzle): precision 99.0 -> 99.2, recall 100.
Golden masters: PHP Extracted Dependencies only (13 files: 231 junk tokens
out, 20 real include expressions in or corrected), firewall imports_unknown
10501 -> 10290, plus Composition Fit ripple. No kept `use` import changed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YAtpBfGGyBGGovitSVaM5Q
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol merged commit 0cb5a1e into main Sep 25, 2026
36 checks passed
@squid-protocol
squid-protocol deleted the claude/festive-fermat-kojuy7 branch September 25, 2026 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PHP _dependency_capture captures multi-line code blocks as import tokens

2 participants