Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sakarikl opened this issue Feb 3, 2022 · 2 comments
Closed
Labels
Milestone

Comments

@sakarikl
Copy link

sakarikl commented Feb 3, 2022

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

@puniserv
Copy link

@github-actions
Copy link

github-actions bot commented Aug 1, 2023

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants