phalcon/cphalcon · error · Phalcon\Messages\Exceptions\MessageNotObject

The message must be an instance of MessageInterface

Error message

The message must be an instance of MessageInterface

What it means

offsetSet() guard on message collections: assigning via array syntax ($messages[0] = ...) requires the value to be an object implementing MessageInterface; anything else (string, array, plain object) is rejected.

Solutions

  1. Assign a Phalcon\Messages\Message instance (or any MessageInterface implementation)
  2. Wrap raw strings in a new Message(value) before assignment
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at phalcon/Messages/Traits/MessagesHelperTrait.zep:111 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at phalcon/Messages/Traits/MessagesHelperTrait.zep:111

            return message;
        }

        return null;
    }

    /**
     * Sets an attribute using the array-syntax
     *
     *```php
     * $messages[0] = new \Phalcon\Messages\Message("This is a message");
     *```
     *
     * @throws MessageNotObject
     */
    public function offsetSet(mixed offset, var value) -> void
    {
        if typeof value !== "object" || !(value instanceof MessageInterface) {
            throw new MessageNotObject();
        }

        if (offset === null) {
            let this->messages[] = value;
        } else {
            let this->messages[offset] = value;
        }
    }

    /**
     * Removes a message from the list
     *
     *```php
     * unset($message["database"]);
     *```
     */
    public function offsetUnset(mixed offset) -> void
    {

View on GitHub (pinned to b7419de9cd)