Skip to content

Commit 6db6de5

Browse files
ptomuliksebastianbergmann
authored andcommitted
fix issue #5567
1 parent ef31134 commit 6db6de5

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/Util/Exporter.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use function is_array;
1313
use function is_scalar;
14+
use SebastianBergmann\RecursionContext\Context;
1415

1516
/**
1617
* @internal This class is not covered by the backward compatibility promise for PHPUnit
@@ -26,7 +27,7 @@ public static function export(mixed $value, bool $exportObjects = false): string
2627
return '{enable export of objects to see this value}';
2728
}
2829

29-
private static function isScalarOrArrayOfScalars(mixed $value): bool
30+
private static function isScalarOrArrayOfScalars(mixed &$value, Context $context = null): bool
3031
{
3132
if (is_scalar($value)) {
3233
return true;
@@ -36,8 +37,19 @@ private static function isScalarOrArrayOfScalars(mixed $value): bool
3637
return false;
3738
}
3839

39-
foreach ($value as $_value) {
40-
if (!self::isScalarOrArrayOfScalars($_value)) {
40+
if (!$context) {
41+
$context = new Context;
42+
}
43+
44+
if ($context->contains($value) !== false) {
45+
return true;
46+
}
47+
48+
$array = $value;
49+
$context->add($value);
50+
51+
foreach ($array as &$_value) {
52+
if (!self::isScalarOrArrayOfScalars($_value, $context)) {
4153
return false;
4254
}
4355
}

0 commit comments

Comments
 (0)