{"record":{"id":"d58acbe69509137e","repo":"phalcon/cphalcon","slug":"no-class-set-for-service-name","errorCode":null,"errorMessage":"No class set for service '{name}'","messagePattern":"No class set for service '(.+?)'","errorType":"exception","errorClass":"Phalcon\\Container\\Exceptions\\NoClassSet","httpStatus":null,"severity":"error","filePath":"phalcon/Container/Definition/ServiceDefinition.zep","lineNumber":240,"sourceCode":"     * Returns the arguments\n     *\n     * @return array\n     */\n    public function getArguments() -> array\n    {\n        return this->arguments;\n    }\n\n    /**\n     * Returns the class\n     *\n     * @return string\n     * @throws NoClassSet\n     */\n    public function getClass() -> string\n    {\n        if (this->className === null) {\n            throw new NoClassSet(this->serviceName);\n        }\n\n        return this->className;\n    }\n\n    /**\n     * Returns the constructor arguments\n     *\n     * @return array\n     */\n    public function getConstructorArgs() -> array\n    {\n        return this->constructorArgs;\n    }\n\n    /**\n     * Returns the extenders\n     *","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Container/Definition/ServiceDefinition.zep#L222-L258","documentation":"ServiceDefinition::getClass() returns the stored class name and throws NoClassSet when the definition has none. Definitions created from closures or pre-built objects (ClosureProcessor/ObjectProcessor) only carry a factory, never a class name, so getClass() is invalid for them. The companion hasClass() exists exactly for this check.","triggerScenarios":"Calling getClass() on a definition returned by set('x', fn () => new Thing()); calling getClass() on a definition built with newDefinition() before setClass(); generic code that iterates all definitions assuming each has a class.","commonSituations":"Debug panels, compilers, or tooling that reflect over every definition; refactoring a service from class-based to factory-based without updating the code that reads getClass().","solutions":["Guard with $definition->hasClass() before calling getClass()","If the definition should instantiate a class, call setClass(ClassName::class)","If you need the instance rather than metadata, use the container's get()/buildService() path instead","Treat hasClass() false + hasFactory() true as a normal factory-style definition"],"exampleFix":"// before\n$class = $container->getDefinition('helper')->getClass(); // NoClassSet\n\n// after\n$def = $container->getDefinition('helper');\n$class = $def->hasClass() ? $def->getClass() : null;","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function definitionClassOrNull(\\Phalcon\\Container\\Definition\\ServiceDefinition $def): ?string\n{\n    return $def->hasClass() ? $def->getClass() : null;\n}","tryCatchPattern":"use Phalcon\\Container\\Exceptions\\NoClassSet;\n\ntry {\n    $class = $def->getClass();\n} catch (NoClassSet $e) {\n    $class = null; // factory/object definition: use hasFactory()/getFactory() instead\n}","preventionTips":["Always pair getClass() with hasClass() in generic code","Know the definition kinds: string definitions have classes; closure/object definitions have factories","Keep reflection over definitions in one utility function with both guards"],"tags":["di-container","definition","no-class-set","phalcon"],"backgroundTag":"invalid-container-definition","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}