{"record":{"id":"2406d715ec618b9c","repo":"phalcon/cphalcon","slug":"invalid-data-to-validate","errorCode":null,"errorMessage":"Invalid data to validate","messagePattern":"Invalid data to validate","errorType":"exception","errorClass":"Phalcon\\Filter\\Validation\\Exceptions\\InvalidValidationData","httpStatus":null,"severity":"error","filePath":"phalcon/Filter/Validation.zep","lineNumber":644,"sourceCode":"            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;\n        } elseif !empty this->data {\n            // else, if data === null, but we have this->data from bind(), reuse this->data\n            let inputData = this->data;\n        }\n\n        if entity !== null {\n            // if user provided entity, bind and assign the data to the entity\n            this->bind(entity, inputData, whitelist);\n        }\n\n        /**\n         * Validation classes can implement the 'beforeValidation' callback\n         */\n        if method_exists(this, \"beforeValidation\") {\n            let status = this->{\"beforeValidation\"}(inputData, this->entity, this->messages);","sourceCodeStart":626,"sourceCodeEnd":662,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Filter/Validation.zep#L626-L662","documentation":"When you pass $data to Validation::validate(), it must be an array or an object (entity-like source); null is treated as 'use previously bound data'. InvalidValidationData is thrown when a non-null scalar is passed — a string, int, float, or bool.","triggerScenarios":"$validation->validate($request->getRawBody()) passing the raw JSON string; validate('name=Tom&age=30') passing a query string; validate(0) or validate(true) from a mis-typed variable.","commonSituations":"Forgetting json_decode() on JSON request bodies in REST endpoints; passing a serialized string instead of the decoded array; template/request objects whose accessor returns a scalar being handed straight to validate().","solutions":["Decode string payloads first: $validation->validate(json_decode($rawBody, true))","Pass arrays ($_POST, model arrays, hydrator output) or an entity object","For query strings parse them: parse_str($qs, $data)"],"exampleFix":"// before\n$messages = $validation->validate($request->getRawBody()); // raw JSON string -> throws\n\n// after\n$data = json_decode($request->getRawBody(), true) ?: [];\n$messages = $validation->validate($data);","handlingStrategy":"type-guard","validationCode":"if ($data !== null && !is_array($data) && !is_object($data)) {\n    throw new InvalidArgumentException('Validation data must be array|object|null, got ' . get_debug_type($data));\n}\n$messages = $validation->validate($data);","typeGuard":"function isPayloadCandidate($data): bool\n{\n    return $data === null || is_array($data) || is_object($data);\n}","tryCatchPattern":"use Phalcon\\Filter\\Validation\\Exceptions\\InvalidValidationData;\ntry {\n    $messages = $v->validate($payload);\n} catch (InvalidValidationData $e) {\n    $decoded = json_decode((string) $payload, true);\n    $messages = is_array($decoded) ? $v->validate($decoded) : throw $e;\n}","preventionTips":["Always json_decode() request bodies before validate()","Type-hint boundary handlers: function validateRequest(array $data)","Beware of string returns from request accessors in error/edge paths"],"tags":["phalcon","validation","input-data","json","type-error"],"backgroundTag":"invalid-validation-data","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}