phalcon/cphalcon · error · Phalcon\Mvc\Micro\Exceptions\HandlerNotCallable

'after' handler is not callable

Error message

'after' handler is not callable

What it means

Thrown by Micro::handle while running 'after' middleware when an entry is neither a MiddlewareInterface instance nor callable. Ensure every after handler is callable or implements MiddlewareInterface.

Solutions

  1. Register only callables or MiddlewareInterface implementations with after()
  2. Validate middleware entries before adding them to the app
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at phalcon/Mvc/Micro.zep:580 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/047b9f55325aa1b9. Report an issue: GitHub.

Appendix: source

Thrown at phalcon/Mvc/Micro.zep:580

                    this->eventsManager->fire("micro:afterExecuteRoute", this);
                }

                let afterHandlers = this->afterHandlers;

                let this->stopped = false;

                /**
                 * Calls the after handlers
                 */
                for after in afterHandlers {
                    if typeof after === "object" && after instanceof MiddlewareInterface {
                        /**
                         * Call the middleware
                         */
                        let status = after->call(this);
                    } else {
                        if unlikely !is_callable(after) {
                            throw new HandlerNotCallable("after");
                        }

                        let status = call_user_func(after);
                    }

                    /**
                     * break the execution if the middleware was stopped
                     */
                    if this->stopped {
                        break;
                    }
                }
            } else {
                 /**
                  * Calling beforeNotFound event
                  */
                if this->eventsManager !== null {
                    if this->eventsManager->fire("micro:beforeNotFound", this) === false {

View on GitHub (pinned to b7419de9cd)