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

Support for array shape for ArrayAccess classes not working. #8549

Open
lulco opened this issue Dec 18, 2022 · 4 comments
Open

Support for array shape for ArrayAccess classes not working. #8549

lulco opened this issue Dec 18, 2022 · 4 comments
Labels
Milestone

Comments

@lulco
Copy link

lulco commented Dec 18, 2022

Bug report

In #7619 there is mentioned the way how to use array shape for ArrayAccess https://phpstan.org/r/95a7bcea-3198-4297-8770-823861adacfb but it seems it is not working anymore. Can you please check it? Thank you very much.

@ondrejmirtes
Copy link
Member

Broke in this PR: phpstan/phpstan-src#1623

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Dec 18, 2022
@phpstan-bot
Copy link
Contributor

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

@@ @@
+PHP 8.1 (6 errors)
+==========
+
+21: Return type mixed of method Options::offsetGet() is not covariant with tentative return type mixed of method ArrayAccess::offsetGet().
 45: Dumped type: string
+46: Cannot assign offset 'name' to Options<array<string, string>>.
+46: Options<array{name: string}> does not accept string.
+47: Cannot assign offset 'name' to Options<array<string, string>>.
+47: Options<array{name: string}> does not accept int.
+
+PHP 7.1 – 8.0 (5 errors)
+==========
+
+45: Dumped type: string
+46: Cannot assign offset 'name' to Options<array<string, string>>.
+46: Options<array{name: string}> does not accept string.
+47: Cannot assign offset 'name' to Options<array<string, string>>.
 47: Options<array{name: string}> does not accept int.
Full report

PHP 8.1 (6 errors)

Line Error
21 Return type mixed of method Options::offsetGet() is not covariant with tentative return type mixed of method ArrayAccess::offsetGet().
45 Dumped type: string
46 Cannot assign offset 'name' to Options<array<string, string>>.
46 Options<array{name: string}> does not accept string.
47 Cannot assign offset 'name' to Options<array<string, string>>.
47 Options<array{name: string}> does not accept int.

PHP 7.1 – 8.0 (5 errors)

Line Error
45 Dumped type: string
46 Cannot assign offset 'name' to Options<array<string, string>>.
46 Options<array{name: string}> does not accept string.
47 Cannot assign offset 'name' to Options<array<string, string>>.
47 Options<array{name: string}> does not accept int.

@VincentLanglet
Copy link
Contributor

I take a look at this and:

@rvanvelzen Since both of the PR were made by you, can you help me on this ?
Do you see the issue ?

@phpstan-bot
Copy link
Contributor

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

@@ @@
+PHP 8.1 (6 errors)
+==========
+
+21: Return type mixed of method Options::offsetGet() is not covariant with tentative return type mixed of method ArrayAccess<key-of<TArray of array>,value-of<TArray of array>>::offsetGet().
 45: Dumped type: string
+46: Cannot assign offset 'name' to Options<array<string, string>>.
+46: Options<array{name: string}> does not accept string.
+47: Cannot assign offset 'name' to Options<array<string, string>>.
+47: Options<array{name: string}> does not accept int.
+
+PHP 7.1 – 8.0 (5 errors)
+==========
+
+45: Dumped type: string
+46: Cannot assign offset 'name' to Options<array<string, string>>.
+46: Options<array{name: string}> does not accept string.
+47: Cannot assign offset 'name' to Options<array<string, string>>.
 47: Options<array{name: string}> does not accept int.
Full report

PHP 8.1 (6 errors)

Line Error
21 Return type mixed of method Options::offsetGet() is not covariant with tentative return type mixed of method ArrayAccess<key-of<TArray of array>,value-of<TArray of array>>::offsetGet().
45 Dumped type: string
46 Cannot assign offset 'name' to Options<array<string, string>>.
46 Options<array{name: string}> does not accept string.
47 Cannot assign offset 'name' to Options<array<string, string>>.
47 Options<array{name: string}> does not accept int.

PHP 7.1 – 8.0 (5 errors)

Line Error
45 Dumped type: string
46 Cannot assign offset 'name' to Options<array<string, string>>.
46 Options<array{name: string}> does not accept string.
47 Cannot assign offset 'name' to Options<array<string, string>>.
47 Options<array{name: string}> does not accept int.

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

4 participants