{"record":{"id":"84d3cdb81f024393","repo":"phalcon/cphalcon","slug":"translate-is-an-immutable-arrayaccess-object","errorCode":null,"errorMessage":"Translate is an immutable ArrayAccess object","messagePattern":"Translate is an immutable ArrayAccess object","errorType":"exception","errorClass":"Phalcon\\Translate\\Exceptions\\ImmutableObject","httpStatus":null,"severity":"error","filePath":"phalcon/Translate/Adapter/AbstractAdapter.zep","lineNumber":108,"sourceCode":"     * Returns the translation related to the given key\n     *\n     * @param string $offset\n     *\n     * @return string\n     */\n    public function offsetGet(mixed offset) -> string\n    {\n        return this->query(offset);\n    }\n\n    /**\n     * Sets a translation value\n     *\n     * @throws ImmutableObject\n     */\n    public function offsetSet(var offset, var value) -> void\n    {\n        throw new ImmutableObject();\n    }\n\n    /**\n     * Unsets a translation from the dictionary\n     *\n     * @throws ImmutableObject\n     */\n    public function offsetUnset(var offset) -> void\n    {\n        throw new ImmutableObject();\n    }\n\n    /**\n     * Returns the translation string of the given key\n     *\n     * @phpstan-param translate_placeholders $placeholders\n     */\n    public function t( string translateKey, array placeholders = []) -> string","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Translate/Adapter/AbstractAdapter.zep#L90-L126","documentation":"Phalcon translate adapters implement ArrayAccess read-only: offsetSet() unconditionally throws Phalcon\\Translate\\Exceptions\\ImmutableObject (phalcon/Translate/Adapter/AbstractAdapter.zep:108). Translations are loaded once at construction (CSV file, array, gettext catalogs) and the dictionary cannot be mutated through array syntax afterwards.","triggerScenarios":"$translate['greeting'] = 'Hello'; on any Phalcon\\Translate\\Adapter\\* instance (NativeArray, Csv, Gettext). Triggered directly or via code that blindly writes to ArrayAccess objects (caches, hydrators, serializers).","commonSituations":"Trying to override one string for a test or A/B experiment; attempting lazy addition of new keys at runtime; porting code that used a plain array for translations before introducing the adapter.","solutions":["Rebuild the adapter with the modified source data (merge into the content array / regenerate the CSV) and swap the service in the DI container.","Apply overrides before construction by merging arrays, not after.","Catch Phalcon\\Translate\\Exceptions\\ImmutableObject if third-party code writes to ArrayAccess and you cannot change it."],"exampleFix":"// before\n$t['greeting'] = 'Hi'; // throws ImmutableObject\n\n// after\n$messages = require app_path('messages/en.php');\n$messages['greeting'] = 'Hi';\n$t = new NativeArray($interpolatorFactory, ['content' => $messages]);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"use Phalcon\\Translate\\Exceptions\\ImmutableObject;\n\ntry {\n    $t[$key] = $value; // third-party code that mutates ArrayAccess\n} catch (ImmutableObject $e) {\n    $logger->warning('Translate adapters are immutable; rebuild the adapter instead');\n}","preventionTips":["Treat the adapter as read-only by design; apply all overrides to the source array before construction.","If runtime overrides are genuinely needed, wrap the adapter in your own class that merges results at read time.","Audit serializers/cachers that write back into ArrayAccess objects."],"tags":["phalcon","translate","immutable","arrayaccess","i18n"],"backgroundTag":"immutable-object-mutation","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}