I have a code generator, which developers run on their local computers where they can use different versions of php and operation systems. So, there's a different behaviour of json_encode with pretty print between php 5.5 on mac os x and linux.
mac os x:
php -r "echo json_encode(['a' => []], JSON_PRETTY_PRINT);"
{
"a": []
}
linux:
php -r "echo json_encode(['a' => []], JSON_PRETTY_PRINT);"
{
"a": [
]
}
Since this json is to be commited to git repo it has to be the same no matter what php build was used.
Could anyone say why there is such a difference and what can I do? Right now, I have only one solution to make something like:
$generated_code = preg_replace("#\\[\s+\\]#", "[]", $generated_code);