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
<?php declare(strict_types = 1); enum Foo { case Bar; case Baz; case Gar; case Gaz; public function startsWithB(): bool { return inArray($this, [static::Baz, static::Bar]); } } /** * @template T * @psalm-param T $needle * @psalm-param array<array-key, T> $haystack */ function inArray(mixed $needle, array $haystack): bool { return \in_array($needle, $haystack, true); }
Phpstan gives an error in the Foo::startsWithB function:
Foo::startsWithB
Parameter #2 $haystack of function inArray expects array<$this(Foo)>, array<int, Foo::Bar|Foo::Baz> given.
It seems to that $this(Foo) does not match Foo::Bar|Foo::Baz, whereas I think that it should.
$this(Foo)
Foo::Bar|Foo::Baz
https://phpstan.org/r/102df9d0-30af-4810-a9de-d3e4ba87fe5f
I don't think that it should be an error at all.
As a side note, Psalm doesn't get an error: https://psalm.dev/r/87ee1f1051
I love generics provided by both phpstan and psalm. It allows me to write much more clean and succinct code.
The text was updated successfully, but these errors were encountered:
@ndench After the latest commit in 1.8.x, PHPStan now reports different result with your code snippet:
@@ @@ -PHP 8.1 (1 error) +PHP 8.1 ========== -11: Parameter #2 $haystack of function inArray expects array<$this(Foo)>, array<int, Foo::Bar|Foo::Baz> given. +No errors PHP 7.1 – 8.0 (2 errors) ==========
No errors
Syntax error, unexpected T_STRING on line 3
Syntax error, unexpected '}', expecting EOF on line 13
Sorry, something went wrong.
phpstan/phpstan-src@c7eef58
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
Bug report
Code snippet that reproduces the problem
Phpstan gives an error in the
Foo::startsWithB
function:It seems to that
$this(Foo)
does not matchFoo::Bar|Foo::Baz
, whereas I think that it should.https://phpstan.org/r/102df9d0-30af-4810-a9de-d3e4ba87fe5f
Expected output
I don't think that it should be an error at all.
As a side note, Psalm doesn't get an error: https://psalm.dev/r/87ee1f1051
Did PHPStan help you today? Did it make you happy in any way?
I love generics provided by both phpstan and psalm. It allows me to write much more clean and succinct code.
The text was updated successfully, but these errors were encountered: