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

Inconsistency of SplFixedArray member types when iterating vs array-access #5358

Closed
dktapps opened this issue Jul 21, 2021 · 4 comments
Closed
Labels
Milestone

Comments

@dktapps
Copy link
Contributor

dktapps commented Jul 21, 2021

Bug report

Code snippet that reproduces the problem

https://phpstan.org/r/1452c341-14e6-41bd-97ad-c48781322eb3

Expected output

The types should be the same (both should be int|null).

Did PHPStan help you today? Did it make you happy in any way?

It helps me every time I make a commit by trapping bugs that would take me hours to find by hand. 👍

@ondrejmirtes
Copy link
Member

Hi, thank you for your kind words!

This should be fixable easily by modifying the stub here: https://github.com/phpstan/phpstan-src/blob/da3790efa9f5ee96c3b7905342904fe3651a29af/stubs/ArrayObject.stub#L89-L108

offsetGet needs to be overriden like this:

	/**
	 * @param TKey $offset
	 * @return TValue
	 */
	public function offsetGet($offset);

Please test the change in NodeScopeResolverTest, thanks.

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Jul 22, 2021
@phpstan-bot
Copy link
Contributor

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

@@ @@
 13: Dumped type: int|null
-14: Dumped type: int
+14: Dumped type: int|null
Full report
Line Error
13 `Dumped type: int
14 `Dumped type: int

@dktapps
Copy link
Contributor Author

dktapps commented Jul 23, 2021

Fixed by phpstan/phpstan-src#587.

@dktapps dktapps closed this as completed Jul 23, 2021
@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 24, 2021
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