Skip to content

[7.x] Fix: restore StatementsAnalyzer's dropped $depth/$root_scope properties#11900

Open
alies-dev wants to merge 1 commit into
vimeo:masterfrom
alies-dev:fix/11899-statementsanalyzer-depth
Open

[7.x] Fix: restore StatementsAnalyzer's dropped $depth/$root_scope properties#11900
alies-dev wants to merge 1 commit into
vimeo:masterfrom
alies-dev:fix/11899-statementsanalyzer-depth

Conversation

@alies-dev

@alies-dev alies-dev commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Context

Merge 290eaec resolved a conflict in StatementsAnalyzer.php by taking 6.x's constructor wholesale while keeping master's analyze() wholesale. That dropped private int $depth = 0;, the $root_scope constructor property, and the constructor logic populating $taint_flow_graph/$variable_use_graph — not just $depth as #11899 describes. Result: PHP 8.2+ crashes (dynamic-property deprecation, converted to an uncaught RuntimeException by Psalm's own ErrorHandler), and even without the crash (e.g. under PHPUnit) unused-variable/taint detection silently no-ops since $variable_use_graph stays null. Confirmed pre-existing via upstream CI on 290eaec2: every unit-test chunk fails across PHP 8.1-8.5.

Solution

Restores all three to match the pre-merge master constructor (5c1c31c62), interleaved with 6.x's later type_variable_tracker addition. All 6 new StatementsAnalyzer(...) call sites already pass the 3rd argument PHP was silently dropping.

Validated: crash gone; full suite 374 failing/erroring tests → 72 (all pre-existing, unrelated); self-analysis 6139 issues → 12 (all pre-existing, unrelated).

Fixes #11899

Merge commit 290eaec (6.x into master) resolved a conflict in
StatementsAnalyzer's property/constructor block by taking 6.x's
version wholesale, while the separate analyze() method kept
master's version wholesale. The two halves no longer matched:

- private int $depth = 0 was dropped, but $this->depth++/-- in
  analyze() remained, causing an uncaught RuntimeException on
  PHP 8.2+ (Psalm's ErrorHandler converts the dynamic-property
  deprecation into a crash).
- The $root_scope constructor-promoted property was dropped too,
  so $this->root_scope always read as an undefined property.
- The constructor logic that populates $this->taint_flow_graph
  and $this->variable_use_graph from the shared codebase graph
  was replaced by 6.x's simpler version, which never assigns
  either property. This silently disabled unused-variable
  detection and taint tracking wherever the crash above didn't
  already stop execution (e.g. under PHPUnit, which doesn't
  install that ErrorHandler).

Restores all three to match the pre-merge master constructor
(commit 5c1c31c) exactly, alongside the type_variable_tracker
logic 6.x legitimately added. Full test suite goes from 374
failing/erroring tests to 72 (all pre-existing/unrelated), and
self-analysis from 6139 issues to 12 (all pre-existing/unrelated).

Fixes vimeo#11899
@alies-dev alies-dev changed the title Fix: restore StatementsAnalyzer's dropped depth/root_scope properties [7.x] Fix: restore StatementsAnalyzer's dropped $depth/$root_scope properties Jul 2, 2026
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.

1 participant