sebastianbergmann / exporter

Provides the functionality to export PHP variables for visualization
BSD 3-Clause "New" or "Revised" License
6.77k stars 34 forks source link

`SplObjectStorage` implements the `SeekableIterator` interface in PHP >= 8.4 #57

Open sebastianbergmann opened 6 months ago

sebastianbergmann commented 6 months ago

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 https://github.com/sebastianbergmann/exporter/issues/49#issuecomment-1711067399

sebastianbergmann commented 6 months ago

https://github.com/php/php-src/pull/13665 has been merged for PHP 8.4.