Skip to content

Commit 0e2b1f0

Browse files
committed
do the version comparison for checking constant
1 parent 46a6c05 commit 0e2b1f0

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/Json.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ private static function saveFile($file, $json)
114114
*/
115115
private static function jsonLastErrorCollections()
116116
{
117-
return [
117+
$collections = [
118118
JSON_ERROR_NONE => null,
119119
JSON_ERROR_DEPTH => [
120120
'message' => 'Maximum stack depth exceeded',
@@ -148,19 +148,25 @@ private static function jsonLastErrorCollections()
148148
'message' => 'Type value given cannot be encoded',
149149
'error-code' => 8,
150150
],
151-
JSON_ERROR_INVALID_PROPERTY_NAME => [
152-
'message' => 'Name value given cannot be encoded',
153-
'error-code' => 9,
154-
],
155-
JSON_ERROR_UTF16 => [
156-
'message' => 'Malformed UTF-16 characters',
157-
'error-code' => 10,
158-
],
159151
'default' => [
160152
'message' => 'Unknown error',
161153
'error-code' => 999,
162154
],
163155
];
156+
157+
if (version_compare(PHP_VERSION, '7.0.0', '>='))
158+
{
159+
$collections[JSON_ERROR_INVALID_PROPERTY_NAME] = [
160+
'message' => 'Name value given cannot be encoded',
161+
'error-code' => 9,
162+
];
163+
$collections[JSON_ERROR_UTF16] = [
164+
'message' => 'Malformed UTF-16 characters',
165+
'error-code' => 10,
166+
];
167+
}
168+
169+
return $collections;
164170
}
165171

166172
/**

0 commit comments

Comments
 (0)