Don't use echo
as a logging mechanism. It's specifically for sending content to the browser. If you want to log things, you need to log them to a file or via error_log
, not via echo
.
I wouldn't have expected anything else other than the data in the response array to be displayed in the console.
This is completely incorrect, and there is absolutely no reason to expect this. $response
is just a random variable, no different from any other variable. PHP doesn't know that you wanted one invocation of echo
to behave differently than your other ones, just because of the name of the variable you passed to it. Everything you echo
goes to the browser, by design. You could try to work around this with output buffers, but don't. Don't use echo
for logging, this is fundamentally at odds with how PHP works.