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.

Solutions

  1. Rebuild the adapter with the modified source data (merge into the content array / regenerate the CSV) and swap the service in the DI container.
  2. Apply overrides before construction by merging arrays, not after.
  3. 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

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


AI-assisted analysis of phalcon/cphalcon@b7419de9cd (2026-08-21). Data as JSON: /api/errors/84d3cdb81f024393. Report an issue: GitHub.

Appendix: 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 = []) -> string

View on GitHub (pinned to b7419de9cd)