{"record":{"id":"6df38889bbac4b0e","repo":"laravel/framework","slug":"self-class-may-not-be-mutated-using-array-acces","errorCode":null,"errorMessage":"{self::class} may not be mutated using array access.","messagePattern":"(.+?) may not be mutated using array access\\.","errorType":"exception","errorClass":"LogicException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/Eloquent/ModelInfo.php","lineNumber":105,"sourceCode":"\n    /**\n     * Get the value for a given offset.\n     *\n     * @throws \\InvalidArgumentException\n     */\n    public function offsetGet(mixed $offset): mixed\n    {\n        return property_exists($this, $offset) ? $this->{$offset} : throw new InvalidArgumentException(\"Property {$offset} does not exist.\");\n    }\n\n    /**\n     * Set the value at the given offset.\n     *\n     * @throws \\LogicException\n     */\n    public function offsetSet(mixed $offset, mixed $value): void\n    {\n        throw new LogicException(self::class.' may not be mutated using array access.');\n    }\n\n    /**\n     * Unset the value at the given offset.\n     *\n     * @throws \\LogicException\n     */\n    public function offsetUnset(mixed $offset): void\n    {\n        throw new LogicException(self::class.' may not be mutated using array access.');\n    }\n}\n","sourceCodeStart":87,"sourceCodeEnd":118,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Database/Eloquent/ModelInfo.php#L87-L118","documentation":"ModelInfo implements ArrayAccess but is read-only. offsetSet always throws a LogicException because model metadata is computed by the framework and must not be mutated at runtime. Attempting $info['key'] = $value triggers this regardless of the offset.","triggerScenarios":"Any assignment through array syntax on a ModelInfo instance: $info['table'] = 'foo' or $info['extra'] = 1.","commonSituations":"Code that decorates or augments inspection data by writing into the same object; generic serializers that try to add a key; copy-paste from a normal array-access object.","solutions":["Do not mutate ModelInfo; read its properties instead.","Build a separate array or DTO if you need derived/extra data: $out = array_merge($info->toArray(), ['extra' => 1]).","Construct a new ModelInfo if you genuinely need different values."],"exampleFix":"// before\n$info['extra'] = 'value'; // throws\n\n// after\n$payload = $info->toArray();\n$payload['extra'] = 'value';","handlingStrategy":"validation","validationCode":"// Never mutate ModelInfo via array access. Copy to array first.\n$payload = $info->toArray();\n$payload['extra'] = 'value'; // mutate the copy, not the object","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat ModelInfo as read-only metadata.","If you need derived fields, build them on a toArray() copy.","Static analysis (phpstan) can flag array writes to ArrayAccess-only objects."],"tags":["eloquent","modelinfo","arrayaccess","immutable"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}