Since upgrading a legacy application from PHP7 to PHP8, I’ve found a change in behaviour with json_encode. Given the following array:
$values = ["a"="a","b"="1"];
$valuesEncoded = json_encode($values);
returns:
{a:"a",b:1}
when in PHP7 it used to return:
{a:"a",b:"1"}
It is causing very many issues when I’m using Javascript to read the result and it’s expecting a string not a number.
I’ve investigated using the flags but the nearest I can find relating to this is JSON_NUMERIC_CHECK which gives the behaviour I’m getting by default, and is the opposite of what I need.
How do I get json_encode to behave like it used to?
3