Skip to content

Assignment inside match statement no longer recognized #13981

Closed

Description

@riasvdv

Bug report

Given a statement like this:

$path = match (true) {
	is_dir($baseDir = dirname(__DIR__).'/lang') => $baseDir,
	default => '/translations',
};

PHPStan reports Variable $baseDir might not be defined.

This was passing in version 2.1.33 and is now an issue in 2.1.34

Code snippet that reproduces the problem

https://phpstan.org/r/93712f26-522b-4374-ad30-f458a3ae7748

Expected output

No errors

Activity

  1. staabm commented on Jan 21, 2026

    @staabm
    Contributor

    git bisect says the error appeared with phpstan/phpstan-src@3beb8c6

    3beb8c626c5c342dead917ff733f2a404d497280 is the first bad commit
    commit 3beb8c626c5c342dead917ff733f2a404d497280
    Author: Ondrej Mirtes <ondrej@mirtes.cz>
    Date:   Thu Dec 11 12:52:24 2025 +0100
    
        Fix match analysis
    
     src/Analyser/NodeScopeResolver.php | 3 +--
     1 file changed, 1 insertion(+), 2 deletions(-)
    bisect found first bad commit
    
  2. added this to the Easy fixes milestone on Feb 10, 2026
  3. added a commit that references this issue on Mar 5, 2026
    afd310d
  4. phpstan-bot commented on Mar 5, 2026

    @phpstan-bot
    Contributor

    Closed via merging phpstan/phpstan-src#5120

  5. added 2 commits that reference this issue on Mar 5, 2026
    375185d
    afd310d
  6. github-actions commented on Apr 6, 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.

  7. locked as resolved and limited conversation to collaborators on Apr 6, 2026
  8. added a commit that references this issue on Apr 7, 2026
    6fe16fe
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

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions