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 is not correctly templated in a foreach #1356

Closed
danog opened this issue Aug 8, 2020 · 2 comments
Closed

SplObjectStorage is not correctly templated in a foreach #1356

danog opened this issue Aug 8, 2020 · 2 comments

Comments

@danog
Copy link

danog commented Aug 8, 2020

Describe the bug
When iterating over an SplObjectStorage, the value is actually the key, intelephense does not account for this.

To Reproduce

<?php

class a
{
    public function method() {}
}
class b
{
    /** @var SplObjectStorage<a, void> */
    public SplObjectStorage $list;
}

$a = new b;
$a->list = new SplObjectStorage;
$a->list->attach(new a);

foreach ($a->list as $key => $object) {
    $key->method();
    $object->method();
}

Screenshots
immagine

Platform and version
Arch, 1.5.3

@bmewburn
Copy link
Owner

bmewburn commented Aug 8, 2020

All iterables and ArrayAccesss currently have a <TKey, TValue> template. If I understand correctly SplObjectStorage would be something like:

class SplObjectStorage<K, V> implements Iterator<int, K>, ArrayAccess<K, V>

This wont happen until #1144

@bmewburn
Copy link
Owner

bmewburn commented Jan 2, 2023

Working in 1.9

@bmewburn bmewburn closed this as completed Jan 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants