PHP command line output buffer outputs regardless of buffer settings

后端 未结 3 1601
轮回少年
轮回少年 2021-02-08 19:28

I have some classes I am writing unit tests for which have echoes in them. I want to suppress this output and thought ob_start() and ob_clean() would s

3条回答
  •  一生所求
    2021-02-08 20:05

    The following solves this problem for me. Without calling ob_end_clean(), the contents of the buffer remain until the script's end, where it is flushed.

    ob_implicit_flush(false);
    ob_start();    
    /*
      ...
      ... do something that pushes countent to the output buffer
      ...
    */    
    $rendered = ob_get_contents();
    ob_end_clean(); // Needed to clear the buffer
    

提交回复
热议问题