From 2fab9f1f95d837597720d9e70885f1e683c22655 Mon Sep 17 00:00:00 2001 From: Najdanovic Ivan Date: Tue, 30 Apr 2019 18:18:51 +0200 Subject: [PATCH] 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 --- src/Elasticsearch/Serializers/ArrayToJSONSerializer.php | 5 +++++ src/Elasticsearch/Serializers/EverythingToJSONSerializer.php | 5 +++++ src/Elasticsearch/Serializers/SmartSerializer.php | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/src/Elasticsearch/Serializers/ArrayToJSONSerializer.php b/src/Elasticsearch/Serializers/ArrayToJSONSerializer.php index a517919db..6c1628cff 100644 --- a/src/Elasticsearch/Serializers/ArrayToJSONSerializer.php +++ b/src/Elasticsearch/Serializers/ArrayToJSONSerializer.php @@ -6,6 +6,11 @@ use Elasticsearch\Common\Exceptions\RuntimeException; +if (!defined('JSON_INVALID_UTF8_SUBSTITUTE')) { + //PHP < 7.2 Define it as 0 so it does nothing + define('JSON_INVALID_UTF8_SUBSTITUTE', 0); +} + /** * Class JSONSerializer * diff --git a/src/Elasticsearch/Serializers/EverythingToJSONSerializer.php b/src/Elasticsearch/Serializers/EverythingToJSONSerializer.php index 14afbb45e..480105cab 100644 --- a/src/Elasticsearch/Serializers/EverythingToJSONSerializer.php +++ b/src/Elasticsearch/Serializers/EverythingToJSONSerializer.php @@ -6,6 +6,11 @@ use Elasticsearch\Common\Exceptions\RuntimeException; +if (!defined('JSON_INVALID_UTF8_SUBSTITUTE')) { + //PHP < 7.2 Define it as 0 so it does nothing + define('JSON_INVALID_UTF8_SUBSTITUTE', 0); +} + /** * Class EverythingToJSONSerializer * diff --git a/src/Elasticsearch/Serializers/SmartSerializer.php b/src/Elasticsearch/Serializers/SmartSerializer.php index 6d0ed81a2..e666dffd2 100644 --- a/src/Elasticsearch/Serializers/SmartSerializer.php +++ b/src/Elasticsearch/Serializers/SmartSerializer.php @@ -7,6 +7,11 @@ use Elasticsearch\Common\Exceptions; use Elasticsearch\Common\Exceptions\Serializer\JsonErrorException; +if (!defined('JSON_INVALID_UTF8_SUBSTITUTE')) { + //PHP < 7.2 Define it as 0 so it does nothing + define('JSON_INVALID_UTF8_SUBSTITUTE', 0); +} + /** * Class SmartSerializer *