0

Closers & dupers, please not that I am asking for a solution which involves configuring Xdebug - no one has offered one of those yet.


Normally, I debug my PHP in Eclipse, but I also allow adding &debug to a URL to do some simple echo and var_dump() to a browser page (for development only).

I know, I know ... debug by printf() ... shudder!

But, it's quick and it works when needed.

My problem is that the generated page is full of

Warning: Cannot modify header information - headers already sent by (output started at ...

with a backtrace.

Is there any way that I can suppress this?

Mawg says reinstate Monica
  • 38,334
  • 103
  • 306
  • 551
  • 2
    Possible duplicate of [How to fix "Headers already sent" error in PHP](http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php) – Qirel Jan 14 '17 at 12:00
  • Nope! Some of these are unavoidable, given that it is debug code (and I don't want to take the effort to fix non-production, given deadline). I just want to suppress them on the page - for debug only. – Mawg says reinstate Monica Jan 14 '17 at 12:22
  • I wouldn't say "Nope!" without reading the actual dupe - it even tells you how to suppress the errors, so clearly you didn't read it fully! Although, *fixing* them would be the better approach. ;-) – Qirel Jan 14 '17 at 12:36
  • OK, I read it - but I am so dumb that I can't see the solution there - can you point it out?. Please note. I don't have time to change a lot of code. I will accept the technical debt & fix it properly next month. – Mawg says reinstate Monica Jan 14 '17 at 13:54

1 Answers1

3

It looks like you are trying to start a session, do a header redirect, set a cookie, etc. after you have outputted your debug information to the browser. And that leads to the warnings you are receiving.

What you could do, is to start output buffering (perhaps conditionally, depending on your debug variable...) at the very top of your script and dump the output at the end of the script or at least after the sections that cause the warnings.

jeroen
  • 91,079
  • 21
  • 114
  • 132
  • 1
    Some very good points. You got me to do what I ought to have done before posting - I actually read those backtarces :-) The culprit appears to be the `ChromePhp` which I use to trace to the browser's developer console. If I don't invoke that when `&debug` is present, the backtrace is not shown – Mawg says reinstate Monica Jan 14 '17 at 12:23