From 7eb922f18c8a13f6761772ae5ee47032a4d33d62 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Tue, 18 Jun 2024 08:31:36 +0200 Subject: [PATCH] Closes #61 --- ChangeLog.md | 7 +++++++ src/Exporter.php | 2 +- tests/ExporterTest.php | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index eaec797..b13b170 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. +## [6.1.1] - 2024-06-18 + +### Fixed + +* [#61](https://github.com/sebastianbergmann/exporter/issues/61): `count(): Recursion detected` warning triggered + ## [6.1.0] - 2024-06-18 ### Added @@ -134,6 +140,7 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt * Remove HHVM-specific code that is no longer needed +[6.1.1]: https://github.com/sebastianbergmann/exporter/compare/6.1.0...6.1.1 [6.1.0]: https://github.com/sebastianbergmann/exporter/compare/6.0.3...6.1.0 [6.0.3]: https://github.com/sebastianbergmann/exporter/compare/fe0dca49a60d34440e2f086951952dd13aa9a5d2...6.0.3 [6.0.2]: https://github.com/sebastianbergmann/exporter/compare/6.0.1...fe0dca49a60d34440e2f086951952dd13aa9a5d2 diff --git a/src/Exporter.php b/src/Exporter.php index 00d8f5a..a368541 100644 --- a/src/Exporter.php +++ b/src/Exporter.php @@ -76,7 +76,7 @@ public function shortenedRecursiveExport(array &$data, ?RecursionContext $proces $processed = new RecursionContext; } - $overallCount = count($data, COUNT_RECURSIVE); + $overallCount = @count($data, COUNT_RECURSIVE); $counter = 0; $export = $this->shortenedCountedRecursiveExport($data, $processed, $counter); diff --git a/tests/ExporterTest.php b/tests/ExporterTest.php index 4eb52e0..0c08177 100644 --- a/tests/ExporterTest.php +++ b/tests/ExporterTest.php @@ -63,6 +63,9 @@ public static function exportProvider(): array $resource = fopen('php://memory', 'r'); fclose($resource); + $recursiveArray = []; + $recursiveArray[0] = &$recursiveArray; + return [ 'null' => [null, 'null', 0], 'boolean true' => [true, 'true', 0], @@ -273,6 +276,17 @@ public static function exportProvider(): array 'SebastianBergmann\Exporter\ExampleIntegerBackedEnum Enum #%d (Value, 0)', 0, ], + 'recursive array' => [ + $recursiveArray, + <<<'EOF' +Array &0 [ + 0 => Array &1 [ + 0 => Array &1, + ], +] +EOF, + 0, + ], ]; } @@ -285,6 +299,9 @@ public static function shortenedExportProvider(): array 'foo' => 'bar', ]; + $recursiveArray = []; + $recursiveArray[0] = &$recursiveArray; + return [ 'null' => [null, 'null'], 'boolean true' => [true, 'true'], @@ -307,6 +324,7 @@ public static function shortenedExportProvider(): array 'enum' => [ExampleEnum::Value, 'SebastianBergmann\Exporter\ExampleEnum Enum (Value)'], 'backed enum (string)' => [ExampleStringBackedEnum::Value, 'SebastianBergmann\Exporter\ExampleStringBackedEnum Enum (Value, \'value\')'], 'backen enum (integer)' => [ExampleIntegerBackedEnum::Value, 'SebastianBergmann\Exporter\ExampleIntegerBackedEnum Enum (Value, 0)'], + 'recursive array' => [$recursiveArray, '[...]', 0], ]; }