Skip to main content
added 75 characters in body
Source Link
user229044
  • 237.2k
  • 41
  • 341
  • 342

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.

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, 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.

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.

Source Link
user229044
  • 237.2k
  • 41
  • 341
  • 342

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, 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.