symfony/var-dumper · error · LogicException
" " object holds non-iterable type " ".
Error message
"%s" object holds non-iterable type "%s".
What it means
Data::getIterator() implements Traversable over the underlying value, but only when that value is an array. Calling it on a Data wrapping a scalar, string, or other non-array type throws a LogicException because iteration is meaningless for those values.
Solutions
- Check the value type before iterating: call $data->getValue() and is_array() it, or use $data->count()/type()
- Only iterate Data objects that wrap arrays; use ->getValue() for scalars
- If the value may be scalar, wrap iteration in an is_array guard
Example fix
// before
foreach ($data as $k => $v) { ... }
// after
$value = $data->getValue();
if (is_array($value)) {
foreach ($value as $k => $v) { ... }
} Defensive patterns
Strategy: type-guard
Validate before calling
$value = $data->getValue();
if (!is_array($value)) {
throw new \LogicException('Expected array value, got '.get_debug_type($value));
} Type guard
function isIterableData(\Symfony\Component\VarDumper\Cloner\Data $data): bool {
return is_array($data->getValue());
} Try / catch
try {
foreach ($data as $k => $v) { /* ... */ }
} catch (\LogicException $e) {
if (str_contains($e->getMessage(), 'non-iterable')) {
// handle scalar: use $data->getValue() directly
} else {
throw $e;
}
} Prevention
- Check $data->getValue() type (or ->getType()) before iterating
- Only feed Data objects wrapping arrays into foreach loops
- Copy out clone results with an is_array check before iteration
When it happens
Trigger: foreach over a Data object whose wrapped value is not an array, e.g. `foreach ($cloned->data as ...)` where the cloned value is a string, int, null, or object.
Common situations: Treating a dumped/cloned variable as always iterable; var-dumper clone results where the top-level value is scalar; code assuming dump output shape without checking the value type first.
Understand the failure class
Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.
Related errors
AI-assisted analysis of symfony/var-dumper@e9d9cf5dcd (2026-09-14).
Data as JSON: /api/errors/4b8b4778a91dfb0b.
Report an issue: GitHub.
Appendix: source
Thrown at Cloner/Data.php:118
}
$recursive[$v->position] = true;
}
$children[$k] = $children[$k]->getValue($recursive);
}
}
return $children;
}
public function count(): int
{
return \count($this->getValue());
}
public function getIterator(): \Traversable
{
if (!\is_array($value = $this->getValue())) {
throw new \LogicException(\sprintf('"%s" object holds non-iterable type "%s".', self::class, get_debug_type($value)));
}
yield from $value;
}
public function __get(string $key): mixed
{
if (null !== $data = $this->seek($key)) {
$item = $this->getStub($data->data[$data->position][$data->key]);
return $item instanceof Stub || [] === $item ? $data : $item;
}
return null;
}
public function __isset(string $key): bool
{View on GitHub (pinned to e9d9cf5dcd)