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 implements the SeekableIterator interface in PHP >= 8.4 #57

Open
sebastianbergmann opened this issue May 5, 2024 · 1 comment

Comments

@sebastianbergmann
Copy link
Owner

sebastianbergmann commented May 5, 2024

SplObjectStorage does not implement the SeekableIterator interface (yet). Therefore we cannot use key() to retrieve the current index before the foreach in https://github.com/sebastianbergmann/exporter/blob/5.0.0/src/Exporter.php#L196 and seek() to restore the index after the loop.

SplObjectStorage objects can also not be cloned reliably. Therefore working around the issue by looping over a clone of the original object is also not an option.

The only thing we can do here is to call rewind() after the loop. Of course, this still changes the index (if it was not on the first element). In most cases, though, I think that changing the index to the first element is "less surprising" than changing it to the last element.

Originally posted by @sebastianbergmann in #49 (comment)

@sebastianbergmann
Copy link
Owner Author

sebastianbergmann commented May 5, 2024

php/php-src#13665 has been merged for PHP 8.4.

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

1 participant