{"record":{"id":"4609a515264f30a9","repo":"phalcon/cphalcon","slug":"service-name-is-not-registered","errorCode":null,"errorMessage":"Service {name} is not registered","messagePattern":"Service (.+?) is not registered","errorType":"exception","errorClass":"Phalcon\\Html\\Exceptions\\ServiceNotRegistered","httpStatus":null,"severity":"error","filePath":"phalcon/Html/TagFactory.zep","lineNumber":212,"sourceCode":"    public function has(string name) -> bool\n    {\n        return isset this->factories[name];\n    }\n\n    /**\n     * Create or return a cached instance of the helper.\n     *\n     * @param string $name\n     *\n     * @return object\n     * @throws \\Phalcon\\Html\\Exception\n     */\n    public function newInstance(string name) -> object\n    {\n        var factory;\n\n        if !isset this->factories[name] {\n            throw new ServiceNotRegistered(name);\n        }\n\n        if !isset this->instances[name] {\n            let factory = this->factories[name];\n            let this->instances[name] = call_user_func(factory);\n        }\n\n        return this->instances[name];\n    }\n\n    /**\n     * Register a helper via a zero-argument Closure. The Closure is invoked on\n     * the first matching `newInstance()` call and its return value is cached.\n     * Passing a new definition clears any cached instance so the next call to\n     * `newInstance()` rebuilds it.\n     *\n     * @param string  $name\n     * @param Closure $definition","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Html/TagFactory.zep#L194-L230","documentation":"Phalcon\\Html\\TagFactory::newInstance() creates helpers from a closure registry keyed by service name ('inputText', 'select', ...). Requesting a name that was never registered throws ServiceNotRegistered from the factory before any helper can be instantiated.","triggerScenarios":"Calling $factory->newInstance('inputData') when the registered service is 'inputText'; requesting a helper key that was renamed or removed between Phalcon versions; forgetting to register a custom helper via set() before requesting it.","commonSituations":"Custom tag helpers registered in DI setup code that runs after first use; upgrades where helper keys changed; typos in helper names passed from configuration or templates.","solutions":["Check the key first: if ($factory->has($name)) { $helper = $factory->newInstance($name); }","Register the custom helper: $factory->set('myHelper', fn() => new MyHelper($deps))","Match the exact service name against the factory's registered keys for your Phalcon version"],"exampleFix":"// before\n$helper = $factory->newInstance('inputData'); // typo, not registered\n\n// after\n$helper = $factory->newInstance('inputText');","handlingStrategy":"validation","validationCode":"if ($factory->has($name)) {\n    $helper = $factory->newInstance($name);\n} else {\n    throw new \\InvalidArgumentException(\"Unknown tag helper service: {$name}\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    $helper = $factory->newInstance($name);\n} catch (\\Phalcon\\Html\\Exceptions\\ServiceNotRegistered $e) {\n    // helper key wrong or unregistered; log the requested name to find the typo\n    $logger->error($e->getMessage());\n    throw $e;\n}","preventionTips":["Register custom helpers in the TagFactory's composition root before first use","Centralize helper names as constants instead of passing raw strings from templates","After upgrading Phalcon, diff the factory's service list against the names your code requests"],"tags":["phalcon","html","tag-factory","service-not-registered","helper"],"backgroundTag":"service-not-registered","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}