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 array_key_exists and cast to array #3821

Closed
keksa opened this issue Sep 2, 2020 · 4 comments
Closed

false positive with array_key_exists and cast to array #3821

keksa opened this issue Sep 2, 2020 · 4 comments
Labels
Milestone

Comments

@keksa
Copy link

keksa commented Sep 2, 2020

Bug report

Code snippet that reproduces the problem

<?php declare(strict_types = 1);

abstract class AbstractMap {}

class HelloWorld
{
    public function fieldExists(AbstractMap $map, string $mapFieldName): bool
    {
        return array_key_exists($mapFieldName, (array) $map);
    }
}

https://phpstan.org/r/74a191d3-489d-430c-adcc-2be1bd1775da

Call to function array_key_exists() with string and array() will always evaluate to false.

Expected output

no issues

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Sep 2, 2020
@phpstan-bot
Copy link
Contributor

@keksa After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
- 9: Call to function array_key_exists() with string and array() will always evaluate to false.
+-1: Internal error: PHPStan\Rules\Methods\WrongCaseOfInheritedMethodRule::findMethod(): Argument #2 ($classReflection) must be of type PHPStan\Reflection\ClassReflection, null given, called in /var/task/vendor/phpstan/phpstan-strict-rules/src/Rules/Methods/WrongCaseOfInheritedMethodRule.php on line 40
+Run PHPStan with --debug option and post the stack trace to:
+https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md
Full report
Line Error
-1 Internal error: PHPStan\Rules\Methods\WrongCaseOfInheritedMethodRule::findMethod(): Argument #2 ($classReflection) must be of type PHPStan\Reflection\ClassReflection, null given, called in /var/task/vendor/phpstan/phpstan-strict-rules/src/Rules/Methods/WrongCaseOfInheritedMethodRule.php on line 40Run PHPStan with --debug option and post the stack trace to:https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md

@phpstan-bot
Copy link
Contributor

@keksa After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-9: Call to function array_key_exists() with string and array() will always evaluate to false.
+9: Call to function array_key_exists() with string and array{} will always evaluate to false.
Full report
Line Error
9 Call to function array_key_exists() with string and array{} will always evaluate to false.

@phpstan-bot
Copy link
Contributor

@keksa After the latest push in 1.8.x, PHPStan now reports different result with your code snippet:

@@ @@
-9: Call to function array_key_exists() with string and array() will always evaluate to false.
+No errors

@github-actions
Copy link

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 27, 2022
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