{"record":{"id":"29eb23e7dc17f84c","repo":"phalcon/cphalcon","slug":"filter-name-is-not-registered","errorCode":null,"errorMessage":"Filter {name} is not registered","messagePattern":"Filter (.+?) is not registered","errorType":"exception","errorClass":"Phalcon\\Filter\\Exceptions\\FilterNotRegistered","httpStatus":null,"severity":"error","filePath":"phalcon/Filter/Filter.zep","lineNumber":215,"sourceCode":"\n        return call_user_func_array([sanitizer, \"__invoke\"], args);\n    }\n\n    /**\n     * Get a service. If it is not in the mapper array, create a new object,\n     * set it and then return it.\n     *\n     * @param string $name\n     *\n     * @return mixed\n     * @throws Exception\n     */\n    public function get(string name) -> var\n    {\n        var definition;\n\n        if (true !== isset(this->mapper[name])) {\n            throw new FilterNotRegistered(name);\n        }\n\n        if (true !== isset(this->services[name])) {\n            let definition           = this->mapper[name],\n                this->services[name] = this->createInstance(definition);\n        }\n\n        return this->services[name];\n    }\n\n    /**\n     * Returns the default sanitizer name to class map. This is the single\n     * source for the built-in sanitizer registry: when adding a sanitizer,\n     * add its `FILTER_*` constant and its entry here.\n     *\n     * @return string[]\n     */\n    public static function getDefaultMapper() -> array","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Filter/Filter.zep#L197-L233","documentation":"Phalcon\\Filter\\Filter is a lazy locator of sanitizers: get(name) resolves the name against its mapper and instantiates the service once. FilterNotRegistered is thrown when the requested name is not in the mapper — neither a built-in filter (alnum, alpha, bool, email, float, absint, int, lower, upper, striptags, trim, string, url, special, regex, replace, remove, ...) nor a custom one registered via set().","triggerScenarios":"$filter->get('slugify') without first calling $filter->set('slugify', SlugFilter::class); a typo like $filter->get('sanitize') or 'upperCase' (the built-in is 'upper'); custom filters registered on a different Filter instance than the one resolving; the DI 'filter' service rebuilt from the default factory, discarding set() calls made earlier.","commonSituations":"Custom sanitizers used in Validation::setFilters() or sanitize() whose registration code was removed in a refactor; names written in config (camelCase vs lowercase mismatch); PHP 8 constructor promotion changes dropping the set() bootstrap; tests building new Filter() per case and forgetting re-registration.","solutions":["Check availability first: if (!$filter->has('slugify')) { $filter->set('slugify', SlugFilter::class); }","Fix the name to match a built-in exactly — e.g. 'upper', 'striptags', 'absint'","Register custom sanitizers once at bootstrap on the shared DI 'filter' service so every consumer sees them"],"exampleFix":"// before\n$value = $filter->sanitize($input, 'slug'); // throws FilterNotRegistered\n\n// after\n$filter->set('slug', SlugFilter::class);\n$value = $filter->sanitize($input, 'slug');","handlingStrategy":"validation","validationCode":"if (!$filter->has('slugify')) {\n    $filter->set('slugify', SlugFilter::class);\n}\nreturn $filter->get('slugify');","typeGuard":"function resolveFilter(\\Phalcon\\Filter\\FilterInterface $filter, string $name)\n{\n    if (!$filter->has($name)) {\n        throw new InvalidArgumentException(\"Unknown filter '{$name}'. Known: \" . implode(', ', array_keys($filter->getMapper?.() ?? [])) );\n    }\n    return $filter->get($name);\n}","tryCatchPattern":"use Phalcon\\Filter\\Exceptions\\FilterNotRegistered;\ntry {\n    $clean = $filter->sanitize($value, 'slugify');\n} catch (FilterNotRegistered $e) {\n    // fall back to a known-safe built-in or fail the request input\n    $clean = $filter->sanitize($value, 'string');\n}","preventionTips":["Register all custom sanitizers in one bootstrap step on the shared DI 'filter' service","Validate filter names coming from config against $filter->has() before use","Keep a project-level list of allowed sanitizer names and reject unknown input-driven names"],"tags":["phalcon","filter","sanitizer","service-locator"],"backgroundTag":"unknown-filter-name","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}