I have got this strange problem lately. I am currently developing a Windows environment when deploying to a Linux server, I know this is not ideal, but at this point I can not do much.
All I do is get the data from the database and then return the JSON response of the resulting array, but the result is different from the problem in my front-end application.
I get this in windows:
{ "id":40, "name":"test" }
and this is on Linux:
{ "id":"40", "name":"test" }
I actually use the Laravel framework, so the syntax is just like this:
$user = User::find($id); return Response::json($user->toArray());
What the scene does:
$this->data = json_encode($data);
Unfortunately, I do not have a hook where you can set the JSON_NUMERIC_CHECK parameter.
Before refactoring my code, is there a way to force JSON_NUMERIC_CHECK on all json_encode calls? I use the same database to retrieve data, so I assume this could be a platform issue?
EDIT:
Further research made me think that database drivers might be guilty. If I reset the data in the windows, I get the following:
array 'id' => int 40 'name' => string 'test' (length=4)
and on Linux it is:
array 'id' => string '40' (length=2) 'name' => string 'test' (length=4)
Ingro source share