Skip to content

Detect assignment to a variable that never goes on to be used #14258

Closed as duplicate

Description

@mikethea1

Feature request

It would be nice if PHPStan could detect assignments to variables that are never used downstream of the assignment. This can help catch dead code and more importantly typos. See for example https://phpstan.org/r/6daee886-df13-4ef5-adb9-a13d96f59415

A nuance is with dynamic variable access ($$x). I think it would be reasonable to treat any downstream dynamic variable access as maybe accessing the current variable so that there wouldn't be spurious errors.

Did PHPStan help you today? Did it make you happy in any way?

No response

Activity

  1. claudepache commented on Mar 10, 2026

    @claudepache

    looks like a duplicate of #12789

  2. mikethea1 commented on Mar 11, 2026

    @mikethea1
    Author

    Good call @claudepache ! Apologies for not finding that before filing.

  3. github-actions commented on Apr 12, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  4. locked as resolved and limited conversation to collaborators on Apr 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions