phalcon/cphalcon · error · Phalcon\Filter\Validation\Exceptions\NoDataToValidate
There is no data to validate
Error message
There is no data to validate
What it means
Validation::getValue(field) reads the current value either from the bound entity or from the bound data. When no entity object is set, it falls back to $this->data and requires that data be an array or object; NoDataToValidate is thrown when it is neither (null, string, int...), meaning there is nothing to read the field from.
Source
Thrown at phalcon/Filter/Validation.zep:432
{
var entity, method, value, data, filters, fieldFilters,
container, filterService;
bool isRawFetched;
let isRawFetched = false;
let entity = this->entity;
let data = this->data;
// If the entity is an object use it to retrieve the values
if typeof entity == "object" {
let value = this->getValueByEntity(entity, field);
if value === null {
let isRawFetched = true;
let value = this->getValueByData(data, field);
}
} else {
if unlikely (typeof data != "array" && typeof data != "object") {
throw new NoDataToValidate();
}
let value = this->getValueByData(data, field);
}
if value === null {
return null;
}
let filters = this->filters;
if fetch fieldFilters, filters[field] {
if fieldFilters {
let container = this->getDI();
if container === null {
let container = Di::getDefault();
if container === null {View on GitHub (pinned to b7419de9cd)
Solutions
- Bind array data first: $validation->bind($entity, $dataArray) or call validate($dataArray)
- json_decode() string payloads into arrays before validating: $data = json_decode($raw, true)
- Ensure getValue() is only called after a successful bind/validate path has populated data or entity
Example fix
// before
$v = new Validation();
$v->add('email', new Email());
$value = $v->getValue('email'); // throws NoDataToValidate: data is null
// after
$v = new Validation();
$v->add('email', new Email());
$value = $v->getValue('email'); // after $v->validate($_POST) or $v->bind(null, $_POST) Defensive patterns
Strategy: validation
Validate before calling
$data = $validation->getData();
if ($validation->getEntity() === null && !is_array($data) && !is_object($data)) {
throw new RuntimeException('No data bound: call bind() or validate($arrayData) before getValue()');
}
return $validation->getValue($field); Type guard
function hasBoundData(\Phalcon\Filter\Validation $v): bool
{
return is_object($v->getEntity()) || is_array($v->getData()) || is_object($v->getData());
} Try / catch
use Phalcon\Filter\Validation\Exceptions\NoDataToValidate;
try {
$value = $v->getValue('email');
} catch (NoDataToValidate $e) {
$value = null; // no payload submitted yet (e.g. first render of an empty form)
} Prevention
- Decode JSON bodies to arrays before validate()/bind()
- Only call getValue() after bind()/validate() has populated entity or data
- Treat 'data === null' as 'form not submitted' and short-circuit before validation
When it happens
Trigger: Calling $validation->getValue('email') before any bind()/validate() set data (property defaults to null); bind($entity, null) with a non-object entity; passing a raw JSON string as data: $v->validate($request->getRawBody()) then getValue() in a validator.
Common situations: Validators that call getValue() during rendering messages when the validation was constructed but never bound; forgetting json_decode() on a request body; data variable lost through an early return before bind().
Related errors
- Unable to insert into {table} without data
- The number of values in the update is not the same as fields
- Incomplete number of bind types
- Matched parameter was not found in parameters list
- Invalid bind parameter (1)
AI-assisted analysis of phalcon/cphalcon@b7419de9cd (2026-08-21).
Data as JSON: /api/errors/2af235cf3884c480.
Report an issue: GitHub.