getRepresentation('iterator')) { return $v; } $c = $v->getContext(); foreach (self::$blacklist as $class) { /** * @psalm-suppress RedundantCondition * Psalm bug #11076 */ if ($var instanceof $class) { $base = new BaseContext($class.' Iterator Contents'); $base->depth = $c->getDepth() + 1; if (null !== ($ap = $c->getAccessPath())) { $base->access_path = 'iterator_to_array('.$ap.', false)'; } $b = new UninitializedValue($base); $b->flags |= AbstractValue::FLAG_BLACKLIST; $v->addRepresentation(new ValueRepresentation('Iterator', $b)); return $v; } } try { $data = \iterator_to_array($var, false); } catch (Throwable $t) { return $v; } if (!\count($data)) { return $v; } $base = new BaseContext('Iterator Contents'); $base->depth = $c->getDepth(); if (null !== ($ap = $c->getAccessPath())) { $base->access_path = 'iterator_to_array('.$ap.', false)'; } $iter_val = $this->getParser()->parse($data, $base); // Since we didn't get TRIGGER_DEPTH_LIMIT and set the iterator to the // same depth we can assume at least 1 level deep will exist if ($iter_val instanceof ArrayValue && $iterator_items = $iter_val->getContents()) { $r = new ContainerRepresentation('Iterator', $iterator_items); $iterator_items = \array_values($iterator_items); } else { $r = new ValueRepresentation('Iterator', $iter_val); $iterator_items = [$iter_val]; } if ((bool) $v->getChildren()) { $v->addRepresentation($r); } else { $v->setChildren($iterator_items); $v->addRepresentation($r, 0); } return $v; } }