symfony/symfony — Issue #2779: CollectionValidator fails to validate ArrayAccess because array_key_exists is used
Author: Entea
Created: 2011-12-03 10:48:40+00:00
State: open

# Problem
CollectionValidator uses array_key_exists to find missing field
```
foreach ($constraint->fields as $field => $constraints) {
if (array_key_exists($field, $value)) {
// cannot simply cast to array, because then the object is converted to an
// array instead of wrapped inside
$constraints = is_array($constraints) ? $constraints : array($constraints);

foreach ($constraints as $constr) {
$walker->walkConstraint($constr, $value[$field], $group, $propertyPath.'['.$field.']');
}

unset($extraFields[$field]);
} else {
$missingFields[] = $field;
}
}

```

# Description
I'm using a so-called POJO as a form data class.
To enable validation, I'm using CollectionValidator.
Of course, to make it work with my form data class, I extend it from **\ArrayAccess** and Traversable
**CollectionValidator** uses **array_key_exists**, which is buggy and does not work with **ArrayAccess**

https://bugs.php.net/bug.php?id=34849
https://bugs.php.net/bug.php?id=41727