Skip to content

Report redundant inline @var tags with reportRedundantVarTag - #6888

Open
jack-worman wants to merge 1 commit into
phpstan:2.3.xfrom
jack-worman:redundant-var-tag
Open

jack-worman wants to merge 1 commit into
phpstan:2.3.xfrom
jack-worman:redundant-var-tag

Conversation

@jack-worman

@jack-worman jack-worman commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Adds an opt-in reportRedundantVarTag parameter that reports an inline @var tag whose type PHPStan already infers (varTag.redundant). It's off by default because IDEs still rely on @var.

  • The engine decides this where it applies the tag, in every pass over the statement, so a tag whose type flows back into what it re-types (through a loop, a by-reference closure, a static variable or an inferred template argument) isn't reported.
  • Not reported either: a tag that changes the type, like the issue's playground example, where @var string widens 'ab'; a tag in a trait; and a tag that overrides another @var for the same variable.
  • turbo-ext's native handlers call the same PHP detector, which only runs with the parameter on, so the detector has no C++ mirror.

Complements #6887 (@phpstan-ignore-var): a redundant tag the IDE still needs can be kept with it, and PHPStan then never applies it.

Closes phpstan/phpstan#5308

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.

report redundant inline @var phpdoc

1 participant