{"record":{"id":"34bdb97241075860","repo":"phalcon/cphalcon","slug":"there-are-no-validators-to-validate","errorCode":null,"errorMessage":"There are no validators to validate","messagePattern":"There are no validators to validate","errorType":"exception","errorClass":"Phalcon\\Filter\\Validation\\Exceptions\\NoValidators","httpStatus":null,"severity":"error","filePath":"phalcon/Filter/Validation.zep","lineNumber":629,"sourceCode":"     * $validation->validate($_POST, $entity, $fields);\n     * ```\n     *\n     * @param array|object $data the data that needs to be validated\n     * @param object $entity the entity object to assign data to\n     * @param array $whitelist only allow these fields to be mutated when entity is used\n     *\n     * @return Messages|false\n     */\n    public function validate(var data = null, var entity = null, array whitelist = []) -> <Messages> | bool\n    {\n        var combinedFieldsValidators, field, scope, status, validator,\n            validatorData, validators, inputData = null;\n\n        let validatorData            = this->validators,\n            combinedFieldsValidators = this->combinedFieldsValidators;\n\n        if unlikely typeof validatorData != \"array\" {\n            throw new NoValidators();\n        }\n\n        /**\n         * Clear pre-calculated values\n         */\n        let this->values = [];\n\n        /**\n         * Implicitly creates a Phalcon\\Messages\\Messages object\n         */\n        let this->messages = new Messages();\n        if (data !== null) {\n            // if data is provided\n            if unlikely typeof data != \"array\" && typeof data != \"object\" {\n                throw new InvalidValidationData();\n            }\n            let this->data = data;\n            let inputData = data;","sourceCodeStart":611,"sourceCodeEnd":647,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Filter/Validation.zep#L611-L647","documentation":"validate() begins by reading $this->validators and requires it to be an array. NoValidators ('There are no validators to validate') is thrown when that property is NOT an array — the property is initialized to [] and setValidators() is typed array, so in practice this means something corrupted or replaced the protected property (a subclass assigning null/false, or an unserialize artifact).","triggerScenarios":"A custom subclass of Validation whose constructor or hook does $this->validators = null; state restored from a broken serialization where the array was lost; legacy code assigning a non-array copied from old tutorials.","commonSituations":"Extending Phalcon\\Filter\\Validation and redeclaring/overwriting $validators without keeping it an array; object caching/session serialization of validation objects that dropped the property.","solutions":["Never overwrite $validators with a non-array — build it with add(), rule(), rules(), or setValidators(array)","In subclasses, call parent::__construct() and mutate via the public API","If the object comes from cache/session, rebuild the validation instead of unserializing a corrupted copy","An empty validator set is legal ([]); no special case is needed for 'no rules'"],"exampleFix":"// before\nclass MyValidation extends Validation\n{\n    public function __construct()\n    {\n        $this->validators = null; // later validate() throws NoValidators\n    }\n}\n\n// after\nclass MyValidation extends Validation\n{\n    public function __construct()\n    {\n        parent::__construct();\n        $this->rule('email', new Email());\n    }\n}","handlingStrategy":"validation","validationCode":"if (!is_array($validation->getValidators())) {\n    throw new RuntimeException('Validation validator map corrupted: rebuild the object instead of reusing it');\n}\n$messages = $validation->validate($data);","typeGuard":null,"tryCatchPattern":"use Phalcon\\Filter\\Validation\\Exceptions\\NoValidators;\ntry {\n    $messages = $v->validate($data);\n} catch (NoValidators $e) {\n    $v->setValidators($this->buildRuleSet()); // rebuild from a known-good source\n    $messages = $v->validate($data);\n}","preventionTips":["Never assign non-arrays to validators/combinedFieldsValidators in subclasses — use add()/setValidators()","Do not unserialize validation objects from cache; rebuild them from definitions","Add a guard in custom constructors that any inherited properties stay arrays"],"tags":["phalcon","validation","validators","state-corruption"],"backgroundTag":"missing-validators","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}