Visitar URL original
Preserve variable flow through declare blocks by drewmt · Pull Request #6693 · phpstan/phpstan-src · GitHub
Skip to content

Preserve variable flow through declare blocks - #6693

Open
drewmt wants to merge 2 commits into
phpstan:2.3.xfrom
drewmt:fix/declare-variable-flow
Open

drewmt wants to merge 2 commits into
phpstan:2.3.xfrom
drewmt:fix/declare-variable-flow

Conversation

@drewmt

@drewmt drewmt commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Fixes phpstan/phpstan#15394.

Variables used inside a declare block are currently reported as unread. The inverse is also missed: assignments inside the block disappear from unused-variable analysis, including a block overwriting a value assigned outside it.

DeclareHandler already processes the nested statements, but drops their VariableFlow when returning the result. Forward that flow in both the PHP handler and its Turbo counterpart, leaving statement-only declarations unchanged. The separate native version bump follows the existing coupling requirement.

The regression covers reads inside a block, writes read afterwards, nested and alternative-syntax blocks, real unused writes, overwritten outer values, and statement-only declarations. It fails before the fix with three false positives and both expected real diagnostics missing.

Validation:

  • All 34 UnusedVariableRuleTest cases pass.
  • Full configured PHP 8.4 suites with and without activated Turbo: 22,452 tests, 96,880 assertions, 106 existing skips each; no failures. Full PHP 8.3 suite: 22,305 tests, 96,631 assertions, 204 existing skips; no failures.
  • Strict native build, differential smoke tests, signature parity (16,390 members), and identical PHP/native traces on the declare fixtures pass.
  • Full self-analysis in both modes, scoped coding standards, syntax and whitespace checks pass.
  • The method/declaration checker reports the same generated-header self mismatch on the clean base and this branch; complete checker output is byte-identical. Those unrelated headers were not regenerated. Local clang-tidy 21 is unavailable; cross-platform and integration CI remain to be checked upstream.

@drewmt

drewmt commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current 2.3.x and refreshed the Turbo pin; the 34 rule tests pass in both modes, along with the native build, smoke tests and signature parity. All twelve downstream failure diagnostic sets on the previous head also occur in the upstream pin-only PR #6696. New-head CI is running.

@drewmt
drewmt force-pushed the fix/declare-variable-flow branch from 55d1b44 to d17834c Compare October 8, 2026 17:32
@drewmt

drewmt commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

Refreshed the rebase after the new Turbo pin conflict, preserving the original fix and upstream commits. Full suites pass in both modes (22,457 tests each), with the rebuilt native version, smoke and signature parity verified. New-head CI is running.

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.

Variable in declare() {} block seems not to be considered used

2 participants