mini\Validator\ValidationError
class
Documentation
Represents validation errors for both scalar values and complex objects
ValidationError provides a unified interface for validation results:
- Stringable: Cast to string for simple error display
- ArrayAccess: Access property errors via $error['fieldName']
- IteratorAggregate: Iterate over property errors with foreach
- JsonSerializable: Export for API responses
Usage
$error = $validator->isInvalid($value);
if ($error) {
// Scalar value - just echo it
echo $error; // "Must be at least 3 characters."
// Object value - access property errors
echo $error['username']; // "Username is required."
echo $error['email']; // "Invalid email format."
// Iterate all property errors
foreach ($error as $field => $fieldError) {
echo "$field: $fieldError\n";
}
// Nested objects
echo $error['address']['city']; // drills down
// JSON for API responses
echo json_encode($error);
}
Inheritance
Implements:
Stringable
ArrayAccess
IteratorAggregate
JsonSerializable
Traversable
Properties (2)
private
Stringable|string $message
private
array $propertyErrors
Methods (11)
Documentation missing
Get the error message
Check if this error has property-level errors
Get all property errors
Documentation missing
Documentation missing
Documentation missing
Documentation missing
Documentation missing
Documentation missing
Documentation missing