{"record":{"id":"d69a916a98be1988","repo":"symfony/var-dumper","slug":"unexpected-stub-type-s","errorCode":null,"errorMessage":"Unexpected Stub type: \"%s\".","messagePattern":"Unexpected Stub type: \"(.+?)\"\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"Cloner/Data.php","lineNumber":373,"sourceCode":"                        if ($cursor->skipChildren) {\n                            $withChildren = false;\n                            $cut = -1;\n                        } else {\n                            $cut = $this->dumpChildren($dumper, $cursor, $refs, $children, $cut, $item->type, null !== $item->class);\n                        }\n                    } elseif ($children && 0 <= $cut) {\n                        $cut += \\count($children);\n                    }\n                    $cursor->skipChildren = false;\n                    $dumper->leaveHash($cursor, $item->type, $item->class, $withChildren, $cut);\n                    break;\n\n                case Stub::TYPE_SCALAR:\n                    $dumper->dumpScalar($cursor, 'default', $item->attr['value']);\n                    break;\n\n                default:\n                    throw new \\RuntimeException(\\sprintf('Unexpected Stub type: \"%s\".', $item->type));\n            }\n        } elseif ('array' === $type) {\n            $dumper->enterHash($cursor, Cursor::HASH_INDEXED, 0, false);\n            $dumper->leaveHash($cursor, Cursor::HASH_INDEXED, 0, false, 0);\n        } elseif ('string' === $type) {\n            $dumper->dumpString($cursor, $item, false, 0);\n        } else {\n            $dumper->dumpScalar($cursor, $type, $item);\n        }\n    }\n\n    /**\n     * Dumps children of hash structures.\n     *\n     * @return int The final number of removed items\n     */\n    private function dumpChildren(DumperInterface $dumper, Cursor $parentCursor, array &$refs, array $children, int $hashCut, int $hashType, bool $dumpKeys): int\n    {","sourceCodeStart":355,"sourceCodeEnd":391,"githubUrl":"https://github.com/symfony/var-dumper/blob/e9d9cf5dcdd4b1b13b4504aaffd66ce4ddb5684e/Cloner/Data.php#L355-L391","documentation":"During Data::dumpItem() traversal, each item's Stub must have a known type (TYPE_REF, TYPE_STRING, TYPE_ARRAY, TYPE_OBJECT, TYPE_RESOURCE, TYPE_SCALAR). An unrecognized Stub->type value indicates a corrupted or hand-built Stub, or an internal var-dumper version incompatibility, and triggers the RuntimeException default-case failure.","triggerScenarios":"Passing a Stub-like object with an out-of-range/unknown ->type constant into the dump pipeline (e.g. custom dumper/cloner code building Stubs manually), or mixing Stub constants from mismatched var-dumper component versions.","commonSituations":"Custom VarDumper extensions or cloned-data manipulation that fabricates Stubs; version drift between symfony/var-dumper cloner and dumper components where Stub::TYPE_* constants changed.","solutions":["Use only Stub::TYPE_* constants when constructing Stubs; verify custom code against symfony/var-dumper's Stub class","Ensure all symfony/var-dumper sub-components (cloner, dumper) are the same installed version (composer update together)","Inspect the item->type value logged in the exception to find who produced the invalid Stub"],"exampleFix":"// before\n$stub->type = 42;\n// after\n$stub->type = Stub::TYPE_OBJECT;","handlingStrategy":"try-catch","validationCode":"$known = [\\Symfony\\Component\\VarDumper\\Cloner\\Stub::TYPE_REF, \\Symfony\\Component\\VarDumper\\Cloner\\Stub::TYPE_STRING, \\Symfony\\Component\\VarDumper\\Cloner\\Stub::TYPE_ARRAY, \\Symfony\\Component\\VarDumper\\Cloner\\Stub::TYPE_OBJECT, \\Symfony\\Component\\VarDumper\\Cloner\\Stub::TYPE_RESOURCE, \\Symfony\\Component\\VarDumper\\Cloner\\Stub::TYPE_SCALAR];\nif (isset($stub->type) && !in_array($stub->type, $known, true)) {\n    throw new \\LogicException('Invalid stub type before dump: '.var_export($stub->type, true));\n}","typeGuard":"function hasValidStubType(?\\Symfony\\Component\\VarDumper\\Cloner\\Stub $stub): bool {\n    return $stub !== null && in_array($stub->type, [\\Symfony\\Component\\VarDumper\\Cloner\\Stub::TYPE_REF, \\Symfony\\Component\\VarDumper\\Cloner\\Stub::TYPE_STRING, \\Symfony\\Component\\VarDumper\\Cloner\\Stub::TYPE_ARRAY, \\Symfony\\Component\\VarDumper\\Cloner\\Stub::TYPE_OBJECT, \\Symfony\\Component\\VarDumper\\Cloner\\Stub::TYPE_RESOURCE, \\Symfony\\Component\\VarDumper\\Cloner\\Stub::TYPE_SCALAR], true);\n}","tryCatchPattern":"try {\n    $dumper->dump($data);\n} catch (\\RuntimeException $e) {\n    if (str_starts_with($e->getMessage(), 'Unexpected Stub type:')) {\n        // log item->type; check component version sync\n    } else {\n        throw $e;\n    }\n}","preventionTips":["Only construct Stubs with Stub::TYPE_* constants","Keep all symfony/var-dumper packages at the same version (composer update together)","Never pass hand-built or foreign Stub objects into the dump pipeline"],"tags":["internal","stub","dumping"],"backgroundTag":"internal-invariant-violation","analyzedSha":"e9d9cf5dcdd4b1b13b4504aaffd66ce4ddb5684e","analyzedAt":"2026-09-14T11:19:53.665Z","contentChangedAt":"2026-09-14T11:19:53.665Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}