I'm trying to return an json object from controller's route
return new JsonResponse($result);
It returns
string(36) "e91a6865-b2a8-4b7d-9351-2eac29f7aa30"
{
//data
}
How can I get rid of the string(36) "e91a6865-b2a8-4b7d-9351-2eac29f7aa30"
?
1 Answer 1
a string(36) "e91a6865-b2a8-4b7d-9351-2eac29f7aa30"
or something similar, that wasn't added to the JsonResponse
, usually is caused by a stray var_dump
/dump
call somewhere in the code base (but in a part that gets evaluated).
Essentially what happens: the var_dump
/dump
is called and it produces the output, and afterwards the output from the Response object (be it the JsonResponse or some other Response) is appended to that.
Options to handle this:
- remember where you put those calls ;o) (works most of the time)
- do not commit any var_dump/dump/dd calls to version control ever (and always do version control!), you'll find the calls easily in the git diff.
- run
grep -nr dump src
in the project root (on linux obviously, replacedump
bydd
if appropriate), this should find the relevant locations in code.
However, overall it's a rather benign source of irritating output.
var_dump(
/dump(
somewhere. you probably should look for itstring(36) "..."
is exactly the output a stray var_dump would produce. It might even be in a different file. or something fishy is going on somewhere else. however, it doesn't have anything to do with the JsonResponse. you can check by returning an empty Response, probably.