{"record":{"id":"38fbf8af04df6ef7","repo":"phalcon/cphalcon","slug":"service-name-not-found","errorCode":null,"errorMessage":"Service '{name}' not found","messagePattern":"Service '(.+?)' not found","errorType":"exception","errorClass":"Phalcon\\Container\\Exceptions\\ServiceNotFound","httpStatus":null,"severity":"error","filePath":"phalcon/Container/Container.zep","lineNumber":170,"sourceCode":"     * Extends the definition\n     *\n     * @param string   $name\n     * @param callable $callable\n     *\n     * @return void\n     * @throws CannotExtendResolved\n     * @throws ServiceNotFound\n     */\n    public function extend(string name, callable callableObject) -> void\n    {\n        let name = this->resolveAlias(name);\n\n        if (array_key_exists(name, this->instances)) {\n            throw new CannotExtendResolved(name);\n        }\n\n        if (!array_key_exists(name, this->services)) {\n            throw new ServiceNotFound(name);\n        }\n\n        this->services[name]->addExtender(callableObject);\n    }\n\n    /**\n     * Resolve and return an element registerd in the container\n     *\n     * @param string $name\n     *\n     * @return mixed\n     * @throws ServiceNotFound\n     */\n    public function get(string name) -> mixed\n    {\n        let name = this->resolveAlias(name);\n\n        if (array_key_exists(name, this->parameters)) {","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Container/Container.zep#L152-L188","documentation":"Thrown by Container::extend() when the service name (after alias resolution) has no entry in the container's service map. extend() attaches a decorator callable that runs after a service is built, and it only works on names already registered with set(); unlike get(), it never autowires or lazily registers a class name. Hitting this means the decoration target does not exist at the time extend() is called.","triggerScenarios":"Calling $container->extend('logger', fn ($logger, $container) => ...) when 'logger' was never passed to set() or registered by a ServiceProvider; passing an alias whose resolved target is not registered; extending before the provider that registers the service has been loaded into the container.","commonSituations":"Provider ordering during bootstrap (extending in provider A a service registered in provider B that runs later), migrating from Phalcon\\Di\\DI where service names differ, assuming extend() lazily creates the service like get() does with autowire, or a simple typo in the service name.","solutions":["Register the service first: $container->set('logger', Logger::class) (or load the ServiceProvider that registers it) before calling extend()","Guard the call: if ($container->hasDefinition('logger')) { $container->extend('logger', $fn); }","Verify the exact name — extend() resolves aliases internally, so the alias target must be a registered service name","If your intent was to decorate an already-built object, register that object with set() instead of extending a definition"],"exampleFix":"// before\n$container->extend('logger', fn ($l) => $l->pushHandler($handler)); // ServiceNotFound\n\n// after\n$container->set('logger', Logger::class);\n$container->extend('logger', fn ($l, $c) => $l->pushHandler($handler));","handlingStrategy":"validation","validationCode":"if ($container->hasDefinition('logger')) {\n    $container->extend('logger', fn ($logger, $c) => $logger->pushHandler($handler));\n} else {\n    throw new LogicException(\"Cannot extend 'logger': service is not registered.\");\n}","typeGuard":null,"tryCatchPattern":"use Phalcon\\Container\\Exceptions\\ServiceNotFound;\n\ntry {\n    $container->extend('logger', $decorator);\n} catch (ServiceNotFound $e) {\n    // register then retry once, or fail with context\n    $container->set('logger', Logger::class);\n    $container->extend('logger', $decorator);\n}","preventionTips":["Register every service before extending it; treat extend() as post-registration decoration only","Centralize service names in constants to avoid typo drift between set() and extend()","In providers, extend services at registration time, not lazily after resolution (that risks CannotExtendResolved)"],"tags":["di-container","service-not-found","extend","phalcon"],"backgroundTag":"service-not-found","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}