{"record":{"id":"1da9b51ffdd3d18a","repo":"symfony/var-dumper","slug":"objects-are-immutable","errorCode":null,"errorMessage":"objects are immutable.","messagePattern":"objects are immutable\\.","errorType":"exception","errorClass":"BadMethodCallException","httpStatus":null,"severity":"error","filePath":"Cloner/Data.php","lineNumber":152,"sourceCode":"\n    public function __isset(string $key): bool\n    {\n        return null !== $this->seek($key);\n    }\n\n    public function offsetExists(mixed $key): bool\n    {\n        return $this->__isset($key);\n    }\n\n    public function offsetGet(mixed $key): mixed\n    {\n        return $this->__get($key);\n    }\n\n    public function offsetSet(mixed $key, mixed $value): void\n    {\n        throw new \\BadMethodCallException(self::class.' objects are immutable.');\n    }\n\n    public function offsetUnset(mixed $key): void\n    {\n        throw new \\BadMethodCallException(self::class.' objects are immutable.');\n    }\n\n    public function __toString(): string\n    {\n        $value = $this->getValue();\n\n        if (!\\is_array($value)) {\n            return (string) $value;\n        }\n\n        return \\sprintf('%s (count=%d)', $this->getType(), \\count($value));\n    }\n","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/symfony/var-dumper/blob/e9d9cf5dcdd4b1b13b4504aaffd66ce4ddb5684e/Cloner/Data.php#L134-L170","documentation":"Data objects are read-only views over cloned dump values. offsetSet() (invoked by ArrayAccess writes like $data[$key] = $value) unconditionally throws BadMethodCallException because Data is intentionally immutable.","triggerScenarios":"Attempting to mutate a Data object with array-write syntax, e.g. `$data['key'] = 'x'` or `$data[] = $value`, including accidental mutation inside loops.","commonSituations":"Developers treating a dump/clone Data handle like a normal array and trying to modify it; mutating dump results to redact values before display.","solutions":["Do not mutate Data; convert first with $data->getValue() or iterator_to_array($data) and modify the plain array","Clone the raw value via $data->getValue(), change it, and re-dump if needed","If you need a mutable structure, build your own array from the Data's contents"],"exampleFix":"// before\n$data['secret'] = '[redacted]';\n// after\n$arr = $data->getValue();\n$arr['secret'] = '[redacted]';","handlingStrategy":"fallback","validationCode":"if ($data instanceof \\Symfony\\Component\\VarDumper\\Cloner\\Data) {\n    // never mutate; copy out first\n    $copy = is_array($v = $data->getValue()) ? $v : (array) $v;\n}","typeGuard":"function mutableCopy(\\Symfony\\Component\\VarDumper\\Cloner\\Data $data): array {\n    return is_array($v = $data->getValue()) ? $v : (array) $v;\n}","tryCatchPattern":"try {\n    $data[$key] = $value;\n} catch (\\BadMethodCallException $e) {\n    // Data is immutable: work on a copied array instead\n    $arr = $data->getValue();\n}","preventionTips":["Treat Data as read-only by design; never use ArrayAccess writes on it","Copy values out to plain arrays before any modification","Document in team code that dump/clone results must not be mutated"],"tags":["immutability","arrayaccess","var-dumper"],"backgroundTag":"unsupported-operation","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"}