Skip to content

Commit

Permalink
Define JSON_INVALID_UTF8_SUBSTITUTE PHP < 7.2
Browse files Browse the repository at this point in the history
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
  • Loading branch information
najdanovicivan committed Apr 30, 2019
1 parent fe6a7ec commit 2fab9f1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Elasticsearch/Serializers/ArrayToJSONSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
5 changes: 5 additions & 0 deletions src/Elasticsearch/Serializers/EverythingToJSONSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
5 changes: 5 additions & 0 deletions src/Elasticsearch/Serializers/SmartSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit 2fab9f1

Please sign in to comment.