-
-
Notifications
You must be signed in to change notification settings - Fork 884
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
Types not being pulled from @phpstan-type correctly #6556
Comments
Looks like the type gets corrupted after the first |
@dehrk After the latest commit in 1.6.x, PHPStan now reports different result with your code snippet: @@ @@
-26: Binary operation "." between '<p>' and array<literal-string&non-empty-string, string>|string results in an error.
-32: Offset 'title' does not exist on array<literal-string&non-empty-string, string>|string.
-33: Offset 'details' does not exist on array<literal-string&non-empty-string, string>|string.
+26: Binary operation "." between '<p>' and array{title: string, details: string}|string results in an error.
+32: Offset 'title' does not exist on array{title: string, details: string}|string.
+33: Offset 'details' does not exist on array{title: string, details: string}|string. Full report
|
@ondrejmirtes After the latest commit in 1.6.x, PHPStan now reports different result with your code snippet: @@ @@
17: Dumped type: array{test1?: string, test2?: string, test3?: array{title: string, details: string}}
-27: Binary operation "." between '<p>' and array<literal-string&non-empty-string, string>|string results in an error.
-31: Dumped type: array<literal-string&non-empty-string, array<literal-string&non-empty-string, string>|string>
-35: Offset 'title' does not exist on array<literal-string&non-empty-string, string>|string.
-36: Offset 'details' does not exist on array<literal-string&non-empty-string, string>|string.
+27: Binary operation "." between '<p>' and array{title: string, details: string}|string results in an error.
+31: Dumped type: array<'test1'|'test2'|'test3', array{title: string, details: string}|string>
+35: Offset 'title' does not exist on array{title: string, details: string}|string.
+36: Offset 'details' does not exist on array{title: string, details: string}|string. Full report
|
@dehrk After the latest push in 1.8.x, PHPStan now reports different result with your code snippet: @@ @@
-26: Binary operation "." between '<p>' and array<literal-string&non-empty-string, string>|string results in an error.
-32: Offset 'title' does not exist on array<literal-string&non-empty-string, string>|string.
-33: Offset 'details' does not exist on array<literal-string&non-empty-string, string>|string.
+26: Offset 'test1'|'test2' does not exist on array{test1?: string, test2?: string, test3?: array{title: string, details: string}}. Full report
|
@dehrk After the latest push in 1.8.x, PHPStan now reports different result with your code snippet: @@ @@
-23: Call to function array_key_exists() with 'test1'|'test2' and array{test3?: array{title: string, details: string}} will always evaluate to false.
+24: Offset 'test1'|'test2' does not exist on array{test3?: array{title: string, details: string}}. Full report
|
@ondrejmirtes After the latest push in 1.8.x, PHPStan now reports different result with your code snippet: @@ @@
17: Dumped type: array{test1?: string, test2?: string, test3?: array{title: string, details: string}}
-27: Binary operation "." between '<p>' and array<literal-string&non-empty-string, string>|string results in an error.
-31: Dumped type: array<literal-string&non-empty-string, array<literal-string&non-empty-string, string>|string>
-35: Offset 'title' does not exist on array<literal-string&non-empty-string, string>|string.
-36: Offset 'details' does not exist on array<literal-string&non-empty-string, string>|string.
+27: Offset 'test1'|'test2' does not exist on array{test1?: string, test2?: string, test3?: array{title: string, details: string}}.
+31: Dumped type: array{test1?: string, test2?: string, test3?: array{title: string, details: string}} Full report
|
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. |
Bug report
When defining array structure with
@phpstan-type
, checking some keys usingarray_key_exists
does not correctly determine the type associated.Code snippet that reproduces the problem
https://phpstan.org/r/2f4d63e8-1e34-4f3d-8d6c-912db0cef960
Expected output
4PHPStan should be able to determine the types for all defined keys. If the keys in the array are not listed in the PHPStan type, it can determine which keys are missing (https://phpstan.org/r/286792cb-f9ef-4536-8751-84f86217ef69).
Did PHPStan help you today? Did it make you happy in any way?
I love PHPstan! It's helping me get my code ready for PHP8 and making it much easier!
The text was updated successfully, but these errors were encountered: