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

SplObjectStorage::removeAll stub problem #9411

Closed
hultberg opened this issue Jun 8, 2023 · 4 comments
Closed

SplObjectStorage::removeAll stub problem #9411

hultberg opened this issue Jun 8, 2023 · 4 comments

Comments

@hultberg
Copy link

hultberg commented Jun 8, 2023

Bug report

Hey there 👋

I have two SplObjectStorage instances. The first is acting like a queue and the last is a collection of all foo objects that has been processed. I'm calling SplObjectStorage::removeAll on the queue storage. I would except no errors since both storages have the same types but in the SplObjectStorage stubs in phpstan the removeAll method has doc \SplObjectStorage<object, mixed>. This causes an error reported by phpstan (see the link to phpstan.org). Intuitively I think the doc should \SplObjectStorage<TObject, TData> (which I have not tested). A quick workaround is to use a @var \SplObjectStorage<object, mixed> $remove but that feels dirty...

Code snippet that reproduces the problem

https://phpstan.org/r/202b8577-bc06-4f29-bd19-11a91d4fd522

Expected output

No error reported because the same storage types are passed.

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

I use phpstan daily and it's a great tool and I love working with it. :-)

@ondrejmirtes
Copy link
Member

/cc @jiripudil This is probably a place where SplObjectStorage::removeAll should allow a call-site covariance once it's implemented, right?

@phpstan-bot
Copy link
Contributor

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

@@ @@
-PHP 8.0 – 8.2 (1 error)
-==========
-
-18: Parameter #1 $storage of method SplObjectStorage<Foo,null>::removeAll() expects SplObjectStorage<object, mixed>, SplObjectStorage<Foo, null> given.
-
-PHP 7.2 – 7.4 (1 error)
-==========
-
-18: Parameter #1 $os of method SplObjectStorage<Foo,null>::removeAll() expects SplObjectStorage<object, mixed>, SplObjectStorage<Foo, null> given.
+No errors

@ondrejmirtes
Copy link
Member

Fixed phpstan/phpstan-src#2892

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 Apr 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants