Skip to content

Commit 82b4218

Browse files
committed
fix: property is passed as integer and cannot be accessed
1 parent 7660882 commit 82b4218

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

src/JsonSchema/Constraints/ObjectConstraint.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ protected function &getProperty(&$element, $property, $fallback = null)
159159
{
160160
if (is_array($element) && (isset($element[$property]) || array_key_exists($property, $element)) /*$this->checkMode == self::CHECK_MODE_TYPE_CAST*/) {
161161
return $element[$property];
162-
} elseif (is_object($element) && property_exists($element, $property)) {
162+
} elseif (is_object($element) && property_exists($element, (string) $property)) {
163163
return $element->$property;
164164
}
165165

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the JsonSchema package.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
namespace JsonSchema\Tests\Constraints;
11+
12+
class PropertyNumberTest extends BaseTestCase
13+
{
14+
protected $validateSchema = true;
15+
16+
public function getInvalidTests(): array
17+
{
18+
return [];
19+
}
20+
21+
public function getValidTests(): array
22+
{
23+
return [
24+
[
25+
'{"some_property":{"some_sub_property":{"4":10,"2":10}}}',
26+
'{
27+
"properties": {
28+
"some_property": {
29+
"type": "object",
30+
"additionalProperties": {
31+
"anyOf": [
32+
{
33+
"type": "object",
34+
"properties": {
35+
"sum": {
36+
"type": "number"
37+
},
38+
"count": {
39+
"type": "number"
40+
}
41+
},
42+
"required": [
43+
"value",
44+
"count"
45+
]
46+
},
47+
{
48+
"type": "object",
49+
"additionalProperties": {
50+
"type": "number"
51+
}
52+
}
53+
]
54+
}
55+
}
56+
},
57+
"type": "object",
58+
"required": [
59+
"some_property"
60+
]
61+
}'
62+
]
63+
];
64+
}
65+
}

0 commit comments

Comments
 (0)