Skip to content

Commit 14443c5

Browse files
author
loucho
committed
Check the element type before making the comparison (== for objects, === for everything else)
1 parent ceddfdf commit 14443c5

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/JsonSchema/Constraints/EnumConstraint.php

+11-3
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,21 @@ class EnumConstraint extends Constraint
2323
public function check($element, $schema = null, $path = null, $i = null)
2424
{
2525
// Only validate enum if the attribute exists
26-
if ($element instanceof UndefinedConstraint && (!isset($schema->required) || !$schema->required)) {
26+
if ($element instanceof UndefinedConstraint && (!isset($schema->required) || !$schema->required)) {
2727
return;
2828
}
2929

3030
foreach ($schema->enum as $enum) {
31-
if ((gettype($element) === gettype($enum)) && ($element === $enum)) {
32-
return;
31+
$type = gettype($element);
32+
if ($type === gettype($enum)) {
33+
if ($type == "object") {
34+
if ($element == $enum)
35+
return;
36+
} else {
37+
if ($element === $enum)
38+
return;
39+
40+
}
3341
}
3442
}
3543

0 commit comments

Comments
 (0)