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

UndefinedVariable with a preg_match() as part of an if statement #4354

Closed
morozov opened this issue Oct 17, 2020 · 1 comment
Closed

UndefinedVariable with a preg_match() as part of an if statement #4354

morozov opened this issue Oct 17, 2020 · 1 comment
Labels

Comments

@morozov
Copy link
Contributor

morozov commented Oct 17, 2020

https://psalm.dev/r/996013af45

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/996013af45
<?php

function test(?string $comment): ?string
{
    if ($comment === null || preg_match('/.*/', $comment, $match) === 0) {
        return null;
    }

    return $match[0];
}
Psalm output (using commit aee4311):

ERROR: UndefinedVariable - 9:12 - Cannot find referenced variable $match

INFO: MixedArrayAccess - 9:12 - Cannot access array value on mixed variable $match

INFO: MixedReturnStatement - 9:12 - Could not infer a return type

INFO: MixedInferredReturnType - 3:34 - Could not verify return type 'null|string' for test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants