-
-
Notifications
You must be signed in to change notification settings - Fork 946
Closed
Labels
Milestone
Description
Bug report
Using this script, PHPStan 0.12.92 complains that the $match variable might be undefined although it would have been defined already when it satisfies the case arm:
<?php declare(strict_types = 1);
function normalize(string $value): string
{
switch (true) {
case strpos($value, 'get_') === 0 && preg_match('/get_(\S+)/m', $value, $match) === 1:
return $match[1]; // Variable $match might not be defined.
default:
return $value;
}
}Code snippet that reproduces the problem
Reproducer:
https://phpstan.org/r/8dbc1625-dadd-40a5-b0ee-baff854ded3d
Proof that it works:
https://3v4l.org/XKsrG
Expected output
No errors.
Did PHPStan help you today? Did it make you happy in any way?
Yes, as always. 😁
Reactions are currently unavailable