Search code examples
phpoutput-buffering

PHP Output buffering contains something before script starts


i have a site, where i buffer some output with

ob_start();
... 

and it worked fine until today i updated my debian from an older php5.3 to the latest php5.3.3-7+squeeze8
Now i sometimes have something in the output buffer before i call it the first time

please don't answer things like

"header must be called before any output is sent." (I know, I work a lot with output buffers)

when i set an extra ob_get_clean(); at the very first line of my script, it works

<?
ob_get_clean();

it seems, like php is creating some output beforehand if i put the first line

<? print_r(ob_get_clean()); ?>

then i see, that there is an empty string already in the buffer:

""

on all other pages it isn't, there ob_get_clean(); contains

null


Solution

  • i found it:

    i had no invisible character in front, it was something different: i called ob_end_clean() one time too much:

    this was my code, inside a function i call:

    function print_something(){
    ob_start();
    
    echo some stuff...
    
    echo ob_get_clean();
    ob_end_clean(); // this was the bug! 
    }
    

    it seems, that you can clear your main output buffer ;)