{"id":"d5019afdb88712de","repo":"laravel/framework","slug":"s-may-not-be-mutated-using-array-access","errorCode":null,"errorMessage":"%s may not be mutated using array access.","messagePattern":"(.+?) may not be mutated using array access\\.","errorType":"exception","errorClass":"LogicException","httpStatus":null,"severity":"warning","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/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Database/Eloquent/ModelInfo.php#L87-L118","documentation":"ModelInfo is intentionally immutable: it is a snapshot of introspection data, so offsetSet() unconditionally throws LogicException to prevent mutation. There is no path that allows writing via array syntax.","triggerScenarios":"Attempting $info['table'] = 'new_table' or any $info[...] = value assignment on a ModelInfo instance.","commonSituations":"Treating ModelInfo like a regular model or array; code written generically against ArrayAccess that tries to write.","solutions":["Do not mutate ModelInfo; build a new value or modify the underlying model/schema instead.","If you need a mutable copy, work with $info->toArray() and change the resulting array.","Refactor generic ArrayAccess consumers to skip write operations for read-only objects."],"exampleFix":"// before\n$info['table'] = 'users'; // throws\n\n// after\n$data = $info->toArray();\n$data['table'] = 'users';","handlingStrategy":"type-guard","validationCode":"// ModelInfo is immutable; copy to array before mutating\n$data = $info->toArray();\n$data[$key] = $value;","typeGuard":"function isMutable(ArrayAccess $obj): bool {\n    return ! ($obj instanceof \\Illuminate\\Database\\Eloquent\\ModelInfo);\n}","tryCatchPattern":null,"preventionTips":["Never write to ModelInfo via array syntax.","Mutate a toArray() copy instead.","Skip write operations in generic ArrayAccess consumers for read-only DTOs."],"tags":["eloquent","introspection","arrayaccess","immutable","read-only"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}