phalcon/cphalcon · error · Phalcon\Translate\Exceptions\ImmutableObject
Translate is an immutable ArrayAccess object
Error message
Translate is an immutable ArrayAccess object
What it means
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.
Source
Thrown at phalcon/Translate/Adapter/AbstractAdapter.zep:108
* Returns the translation related to the given key
*
* @param string $offset
*
* @return string
*/
public function offsetGet(mixed offset) -> string
{
return this->query(offset);
}
/**
* Sets a translation value
*
* @throws ImmutableObject
*/
public function offsetSet(var offset, var value) -> void
{
throw new ImmutableObject();
}
/**
* Unsets a translation from the dictionary
*
* @throws ImmutableObject
*/
public function offsetUnset(var offset) -> void
{
throw new ImmutableObject();
}
/**
* Returns the translation string of the given key
*
* @phpstan-param translate_placeholders $placeholders
*/
public function t( string translateKey, array placeholders = []) -> stringView on GitHub (pinned to b7419de9cd)
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.
Example fix
// before
$t['greeting'] = 'Hi'; // throws ImmutableObject
// after
$messages = require app_path('messages/en.php');
$messages['greeting'] = 'Hi';
$t = new NativeArray($interpolatorFactory, ['content' => $messages]); Defensive patterns
Strategy: try-catch
Try / catch
use Phalcon\Translate\Exceptions\ImmutableObject;
try {
$t[$key] = $value; // third-party code that mutates ArrayAccess
} catch (ImmutableObject $e) {
$logger->warning('Translate adapters are immutable; rebuild the adapter instead');
} Prevention
- 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.
When it happens
Trigger: $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).
Common situations: 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.
Related errors
- Cannot find translation key: {key}
- Parameter 'content' is required
- Error opening translation file '{file}'
- This class requires the gettext extension for PHP
- Parameter 'locale' is required
AI-assisted analysis of phalcon/cphalcon@b7419de9cd (2026-08-21).
Data as JSON: /api/errors/84d3cdb81f024393.
Report an issue: GitHub.