We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Originally posted by hollodotme July 22, 2021
<?php declare(strict_types = 1); $matches = []; $pattern = '#^C\s+(?<productId>\d+)$#i'; $subject = 'C 1234567890'; $found = (bool)preg_match( $pattern, $subject, $matches ) && isset( $matches['productId'] );
LINE ERROR ------------------------------------- 7 Result of && is always false.
See: https://phpstan.org/r/dc55b6b9-5285-4b3c-895f-bb036dd1e2d5
IMO this is a false positive as the second condition isset($matches['productId']) is true after evaluation of the preg_match function.
isset($matches['productId'])
true
preg_match
The $matches array was changed by preg_match() via reference.
$matches
preg_match()
The text was updated successfully, but these errors were encountered:
Looks like PHPStan is a bit confused about already existing $matches variable, without it it works: https://phpstan.org/r/ae249e12-2326-494c-968c-316e503e9768
Sorry, something went wrong.
@ondrejmirtes After the latest commit in dev-master, PHPStan now reports different result with your code snippet:
@@ @@ -No errors +8: Result of && is always false.
Result of && is always false.
Result of || is always true.
isset
phpstan/phpstan-src@989dd6f
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.
No branches or pull requests
Discussed in #5361
Originally posted by hollodotme July 22, 2021
Code
PHPStan Error
See: https://phpstan.org/r/dc55b6b9-5285-4b3c-895f-bb036dd1e2d5
IMO this is a false positive as the second condition
isset($matches['productId'])
istrue
after evaluation of thepreg_match
function.The
$matches
array was changed bypreg_match()
via reference.The text was updated successfully, but these errors were encountered: