{"record":{"id":"d5353ed507e9cc33","repo":"slimphp/Slim","slug":"a-middleware-must-be-an-object-class-name-referenc","errorCode":null,"errorMessage":"A middleware must be an object/class name referencing an implementation of MiddlewareInterface or a callable with a matching signature.","messagePattern":"A middleware must be an object/class name referencing an implementation of MiddlewareInterface or a callable with a matching signature\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"Slim/MiddlewareDispatcher.php","lineNumber":100,"sourceCode":"     *\n     * @param MiddlewareInterface|string|callable $middleware\n     */\n    public function add($middleware): MiddlewareDispatcherInterface\n    {\n        if ($middleware instanceof MiddlewareInterface) {\n            return $this->addMiddleware($middleware);\n        }\n\n        if (is_string($middleware)) {\n            return $this->addDeferred($middleware);\n        }\n\n        if (is_callable($middleware)) {\n            return $this->addCallable($middleware);\n        }\n\n        /** @phpstan-ignore-next-line */\n        throw new RuntimeException(\n            'A middleware must be an object/class name referencing an implementation of ' .\n            'MiddlewareInterface or a callable with a matching signature.'\n        );\n    }\n\n    /**\n     * Add a new middleware to the stack\n     *\n     * Middleware are organized as a stack. That means middleware\n     * that have been added before will be executed after the newly\n     * added one (last in, first out).\n     */\n    public function addMiddleware(MiddlewareInterface $middleware): MiddlewareDispatcherInterface\n    {\n        $next = $this->tip;\n        $this->tip = new class ($middleware, $next) implements RequestHandlerInterface {\n            private MiddlewareInterface $middleware;\n","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/slimphp/Slim/blob/80900fb39cafce3ae53b18a2c4f642a122f03095/Slim/MiddlewareDispatcher.php#L82-L118","documentation":"Error \"A middleware must be an object/class name referencing an implementation of MiddlewareInterface or a callable with a matching signature.\" thrown in slimphp/Slim.","triggerScenarios":"Thrown at Slim/MiddlewareDispatcher.php:100 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"80900fb39cafce3ae53b18a2c4f642a122f03095","analyzedAt":"2026-08-21T01:41:09.580Z","schemaVersion":2},"datasetVersion":"2026-08-21T03:17:12.404Z"}