From 41cdd17bf0b5c85a231fa8a7fb789478658596b6 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Wed, 20 May 2026 07:48:57 +0200 Subject: [PATCH] Closes #57 --- ChangeLog.md | 7 +++++++ src/Exporter.php | 10 +++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index d511c33..7016329 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -2,6 +2,12 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles. +## [8.0.4] - 2026-MM-DD + +### Changed + +* [#57](https://github.com/sebastianbergmann/exporter/issues/57): Preserve `SplObjectStorage` iterator position instead of resetting to first element + ## [8.0.3] - 2026-05-20 ### Fixed @@ -48,6 +54,7 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt * This component is no longer supported on PHP 8.2 +[8.0.4]: https://github.com/sebastianbergmann/exporter/compare/8.0.3...main [8.0.3]: https://github.com/sebastianbergmann/exporter/compare/8.0.2...8.0.3 [8.0.2]: https://github.com/sebastianbergmann/exporter/compare/8.0.1...8.0.2 [8.0.1]: https://github.com/sebastianbergmann/exporter/compare/8.0.0...8.0.1 diff --git a/src/Exporter.php b/src/Exporter.php index 08e577a..dd878b7 100644 --- a/src/Exporter.php +++ b/src/Exporter.php @@ -230,6 +230,12 @@ final readonly class Exporter // above (fast) mechanism nor with reflection in Zend. // Format the output similarly to print_r() in this case if ($value instanceof SplObjectStorage) { + $key = null; + + if ($value->valid()) { + $key = $value->key(); + } + foreach ($value as $_value) { $array['Object #' . spl_object_id($_value)] = [ 'obj' => $_value, @@ -237,7 +243,9 @@ final readonly class Exporter ]; } - $value->rewind(); + if ($key !== null) { + $value->seek($key); + } } return $array;