phalcon/cphalcon · error · Phalcon\Filter\Validation\Exceptions\InvalidValidatorScope
The validator scope is not valid
Error message
The validator scope is not valid
What it means
Combined-field validators (subclasses of AbstractCombinedFieldsValidator registered with an array of fields, e.g. Uniqueness over ['email','domain']) are stored as scopes: [fieldArray, validator]. During validate(), InvalidValidatorScope is thrown when a combined-fields entry is not an array — the internal structure was corrupted, since add() only ever appends well-formed pairs.
Source
Thrown at phalcon/Filter/Validation.zep:696
*/
if this->preChecking(field, validator) {
continue;
}
/**
* Check if the validation must be canceled if this validator fails
*/
if validator->validate(this, field) === false {
if validator->getOption("cancelOnFail") {
break;
}
}
}
}
for scope in combinedFieldsValidators {
if unlikely typeof scope != "array" {
throw new InvalidValidatorScope();
}
let field = scope[0],
validator = scope[1];
if unlikely typeof validator != "object" {
throw new InvalidValidator();
}
/**
* Call internal validations, if it returns true, then skip the
* current validator
*/
if this->preChecking(field, validator) {
continue;
}
/**View on GitHub (pinned to b7419de9cd)
Solutions
- Do not write combinedFieldsValidators directly — register combined validators through add(['field1','field2'], $combinedValidator)
- In subclasses, append with the same [array $fields, ValidatorInterface $validator] tuple shape
- Rebuild cached/serialized validation objects instead of restoring corrupted state
Example fix
// before
class MyValidation extends Validation
{
public function init()
{
$this->combinedFieldsValidators[] = 'userUniqueness'; // string -> throws later
}
}
// after
$this->add(['email', 'domain'], new Uniqueness()); Defensive patterns
Strategy: validation
Validate before calling
// before validating on a hand-built/subclassed Validation, sanity-check the scopes:
$ref = new ReflectionProperty($validation, 'combinedFieldsValidators');
foreach ($ref->getValue($validation) as $scope) {
if (!is_array($scope)) {
throw new RuntimeException('Corrupt combined-fields scope: expected [fields, validator] array');
}
} Type guard
function scopeIsWellFormed($scope): bool
{
return is_array($scope) && isset($scope[0], $scope[1]);
} Try / catch
use Phalcon\Filter\Validation\Exceptions\InvalidValidatorScope;
try {
$messages = $v->validate($data);
} catch (InvalidValidatorScope $e) {
// internal state corrupt: rebuild the validation object from definitions
$v = $this->buildValidation();
$messages = $v->validate($data);
} Prevention
- Register combined-field validators only via add(['f1','f2'], $validator) — never write the scope list by hand
- Avoid serializing/caching Validation instances; rebuild them per request
When it happens
Trigger: A subclass of Validation assigning $this->combinedFieldsValidators = '...' or pushing a non-array entry; unserializing a cached validation object whose scope arrays were lost; third-party code mutating the protected property directly.
Common situations: Custom Validation subclasses that rebuild the combined validator list manually; session/cache serialization of validation state. Not reachable through the public add()/rule()/setValidators() API.
Related errors
- There are no validators to validate
- Unable to insert into {table} without data
- The number of values in the update is not the same as fields
- RETURNING requires at least one column or '*'
- Field must be passed as array of fields or string
AI-assisted analysis of phalcon/cphalcon@b7419de9cd (2026-08-21).
Data as JSON: /api/errors/88c24ed1ee9e4f0b.
Report an issue: GitHub.