{"record":{"id":"762f0b72cd0edb27","repo":"phalcon/cphalcon","slug":"collection-does-not-have-an-annotation-called-na","errorCode":null,"errorMessage":"Collection does not have an annotation called '{name}'","messagePattern":"Collection does not have an annotation called '(.+?)'","errorType":"exception","errorClass":"Phalcon\\Annotations\\Exceptions\\AnnotationNotFound","httpStatus":null,"severity":"error","filePath":"phalcon/Annotations/Collection.zep","lineNumber":99,"sourceCode":"        return annotation;\n    }\n\n    /**\n     * Returns the first annotation that match a name\n     */\n    public function get(string name) -> <Annotation>\n    {\n        var annotation, annotations;\n\n        let annotations = this->annotations;\n\n        for annotation in annotations {\n            if name == annotation->getName() {\n                return annotation;\n            }\n        }\n\n        throw new AnnotationNotFound(name);\n    }\n\n    /**\n     * Returns all the annotations that match a name\n     */\n    public function getAll(string name) -> <Annotation[]>\n    {\n        var annotations, annotation;\n        array found;\n\n        let found = [],\n            annotations = this->annotations;\n\n        for annotation in annotations {\n            if name == annotation->getName() {\n                let found[] = annotation;\n            }\n        }","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Annotations/Collection.zep#L81-L117","documentation":"Phalcon\\Annotations\\Collection::get(name) linearly scans the annotations collected for a class/method/property and returns the first whose name matches. If none matches it throws AnnotationNotFound — the requested annotation simply is not present on that reflection target.","triggerScenarios":"`$collection->get('Cached')` where the target's docblock has no `@Cached` annotation; name case mismatch ('Cached' vs 'cached', comparison is exact); asking an object for an annotation only defined on a parent class (Phalcon reads only the declared docblock by default).","commonSituations":"Optional-behavior code assuming an annotation always exists; renaming an annotation without updating consumers; expecting inherited annotations to be visible; case differences between teams.","solutions":["Guard with `$collection->has('Cached')` before calling get()","Use `$collection->getAll('Cached')` and check the count when multiple same-name annotations may exist","Dump `$collection->getAnnotations()` to see the exact names/case actually parsed, and fix the spelling at either end"],"exampleFix":"// before\n$ann = $collection->get('Cached');\n// after\n$ann = $collection->has('Cached') ? $collection->get('Cached') : null;","handlingStrategy":"validation","validationCode":"if ($collection->has('Cached')) {\n    $annotation = $collection->get('Cached');\n} else {\n    $annotation = null;\n}","typeGuard":"function hasAnnotation(\\Phalcon\\Annotations\\Collection $collection, string $name): bool\n{\n    return $collection->has($name);\n}","tryCatchPattern":"try {\n    $annotation = $collection->get('Cached');\n} catch (\\Phalcon\\Annotations\\Exceptions\\AnnotationNotFound $e) {\n    $annotation = null; // optional behavior\n}","preventionTips":["Treat get() as a must-exist lookup; always pair it with has() when the annotation is optional","Centralize annotation name constants to prevent case/spelling drift","Remember annotations are read from the declared docblock only — do not assume inheritance"],"tags":["annotations","collection","not-found","lookup"],"backgroundTag":"lookup-key-not-found","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}