Skip to content

Dead code reported after while loop processing an array #4070

@UlrichEckhardt

Description

@UlrichEckhardt

Bug report

Versions used:

  • PHP 7.4
  • PHPStan - PHP Static Analysis Tool 0.12.54
  • Installed with Composer 2.0.6

Some code is incorrectly flagged as dead code:

 ------ ------------------------------------------------------- 
  Line   runtest2.php                                           
 ------ ------------------------------------------------------- 
  14     Unreachable statement - code above always terminates.  
 ------ ------------------------------------------------------- 

Notes:

Code snippet that reproduces the problem

<?php

array_shift($argv);

while ($argv) {
    $arg = array_shift($argv);
    if ($arg === 'foo') {
        continue;
    }
    die();
}

echo "finished\n";

https://phpstan.org/r/8b26356d-c711-47b7-97b7-a79f050b8000

Expected output

I'd expect not to get a warning at all.

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