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

Fix issue #5567 #5568

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/Util/Exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use function is_array;
use function is_scalar;
use SebastianBergmann\RecursionContext\Context;

/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
Expand All @@ -26,7 +27,7 @@
return '{enable export of objects to see this value}';
}

private static function isScalarOrArrayOfScalars(mixed $value): bool
private static function isScalarOrArrayOfScalars(mixed &$value, Context $context = null): bool
{
if (is_scalar($value)) {
return true;
Expand All @@ -36,8 +37,19 @@
return false;
}

foreach ($value as $_value) {
if (!self::isScalarOrArrayOfScalars($_value)) {
if (!$context) {
$context = new Context;
}

if ($context->contains($value) !== false) {
return true;

Check warning on line 45 in src/Util/Exporter.php

View check run for this annotation

Codecov / codecov/patch

src/Util/Exporter.php#L45

Added line #L45 was not covered by tests
}

$array = $value;
$context->add($value);

foreach ($array as &$_value) {
if (!self::isScalarOrArrayOfScalars($_value, $context)) {
return false;
}
}
Expand Down