Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[BugFix][Validator] Fix for PHP incosistent behaviour of ArrayAccess

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: #2779
Todo: -

Because PHP function `array_key_exists` is buggy, it works great with native
PHP `ArrayObject` instances, but hand written implementations of `ArrayAccess`
and `Traversable` objects will fail to work with `CollectionValidator`
  • Loading branch information...
commit 70ce3e1528b3e85f0f9000278eb0e25727ffe63a 1 parent e4f9e59
@canni canni authored
Showing with 5 additions and 1 deletion.
  1. +5 −1 Constraints/CollectionValidator.php
View
6 Constraints/CollectionValidator.php
@@ -52,7 +52,11 @@ public function isValid($value, Constraint $constraint)
}
foreach ($constraint->fields as $field => $constraints) {
- if (array_key_exists($field, $value)) {
+ if (
+ // bug fix issue #2779
+ (is_array($value) && array_key_exists($field, $value)) ||
+ ($value instanceof \ArrayAccess && $value->offsetExists($field))
+ ) {
// 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);
Please sign in to comment.
Something went wrong with that request. Please try again.