Skip to content

Commit 2fab9f1

Browse files
Define JSON_INVALID_UTF8_SUBSTITUTE PHP < 7.2
If PHP version is < 7.2 JSON_INVALID_UTF8_SUBSTITUTE is not defined. In such case it can be defined to 0 so that it does not have any effect but the code can still be executed without crashing
1 parent fe6a7ec commit 2fab9f1

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

src/Elasticsearch/Serializers/ArrayToJSONSerializer.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77
use Elasticsearch\Common\Exceptions\RuntimeException;
88

9+
if (!defined('JSON_INVALID_UTF8_SUBSTITUTE')) {
10+
//PHP < 7.2 Define it as 0 so it does nothing
11+
define('JSON_INVALID_UTF8_SUBSTITUTE', 0);
12+
}
13+
914
/**
1015
* Class JSONSerializer
1116
*

src/Elasticsearch/Serializers/EverythingToJSONSerializer.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77
use Elasticsearch\Common\Exceptions\RuntimeException;
88

9+
if (!defined('JSON_INVALID_UTF8_SUBSTITUTE')) {
10+
//PHP < 7.2 Define it as 0 so it does nothing
11+
define('JSON_INVALID_UTF8_SUBSTITUTE', 0);
12+
}
13+
914
/**
1015
* Class EverythingToJSONSerializer
1116
*

src/Elasticsearch/Serializers/SmartSerializer.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
use Elasticsearch\Common\Exceptions;
88
use Elasticsearch\Common\Exceptions\Serializer\JsonErrorException;
99

10+
if (!defined('JSON_INVALID_UTF8_SUBSTITUTE')) {
11+
//PHP < 7.2 Define it as 0 so it does nothing
12+
define('JSON_INVALID_UTF8_SUBSTITUTE', 0);
13+
}
14+
1015
/**
1116
* Class SmartSerializer
1217
*

0 commit comments

Comments
 (0)