Last few weeks I have been working from home for obvious reasons. We run our development environment via a stack of docker microservices for which we have a standard set of docker images and docker-compose files.
At work my stack works 100% without issue with regard to the calls for json_decode
but when I am home and use the same files whenever json_decode is called the process "hangs". Putting some logging after the call is never reached.
One example of the call is
$ret[$row['an']]['sc'] = json_decode($row['channel']);
When the code reaches this it never gets out of it, no errors logged either.
To fix this I have to change the call to the following (please note this is running on PHP version 5.6.40)
$ret[$row['an']]['sc'] = json_decode($row['channel'],false,512,JSON_INVALID_UTF8_IGNORE);
My home dev machine is a Windows PC (Win 10) but I also have a Linux drive which I can boot into but this experiences the same problem.
Additional info:
This is working upon an array of json strings such as
{"phones":["44123456789","44123456788","44123456787"]}
{"phones":[]}
It hangs when the value been worked on is {"phones":[]}
but if the json value has numbers it runs fine.
The json_decode is in fact hanging everything except when the value is NULL. If the value been decoded is null is carries on without issue.
On my work machine where everything runs without issue the data is the same oddly.
Additional info to support comments:
A var_dump of the first item that json is choking on
string(56) "{"phones":["44123456789","447838588850","447838588850"]}"
Output of the byte string for the failing item as per Gavins recommendation:
(
[1] => 7b2270686f6e6573223a5b223434313233343536373839222c22343437383338353838383530222c22343437383338353838383530225d7d
)
I also have tried the three methods outlined in the solution at How to detect malformed utf-8 string in PHP?'%2C%20%24string)%3B and all are returning true (true = valid)
UPDATED 19/06/2020 below
Testing the simple php code below even this fails on the json_decode. Json_encode works fine
<?php
$job[123] = [
'id' => 123,
'position' => [
'title' => 'PHP Developer',
],
];
$json = json_encode($job[123]);
echo($json);
$jsonStr = json_decode($json);
print_r($jsonStr);
```