digitalnature / php-ref

A better alternative to print_r / var_dump
347 stars 59 forks source link

Doctype should not be sent when output buffering is enabled #2

Open matthieusieben opened 11 years ago

matthieusieben commented 11 years ago

I use output buffering to render and cache different parts of a website. Because of that, no headers are sent before everything is rendered. This is detected by headers_sent() returning true in ref.php:43 and causes r() to send the headers every time is is called.

For that reason I replaced line 43 by: if(!headers_sent() && ob_get_level() == 0)

This may not be the best solution (which woud require to check every output buffer's length) but it did the trick for me (I don't use r() before content was sent to the browser).

digitalnature commented 11 years ago

The HTML header was sent every time r() was called (not sure exactly why). Was this the issue? I've added an ob_get_length() check so no HTTP headers and <html> headers will be sent if the internal buffer has content in it.

You should make your own wrapper function and register it with ref::config('shortcutFunc', 'yourFn'); if you need further control over this.