Skip to content

false positive with preg_match and checking match result inside same if #6551

Closed
@sakarikl

Description

@sakarikl

Bug report

<?php declare(strict_types = 1);

$data = [
	'c1' => 12,
	'rasd' => 13,
	'c34' => 15,
];

foreach ($data as $key => $value) {
    $match = [];
    if (false === preg_match('/^c(\d+)$/', $key, $match) || empty($match)) {
        continue;
    }            
    var_dump($key);
    var_dump($value);
}

https://phpstan.org/r/68e9cca9-06c3-48ad-8f3c-4e395f9da991

https://3v4l.org/ZY9FG

Expected output

Expected no errors

If preg_match is done outside of if works as expected

https://phpstan.org/r/66f21acd-abc8-463f-af11-92ac0cb700c0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions