PHP command line output buffer output regardless of buffer settings

I have several classes, I write unit tests for which there are echoes. I want to suppress this conclusion and thought that ob_start() and ob_clean() would be enough, but they have no effect.

 public function testSomething (){ ob_start(); $class = new MyClass(); $class->method(); ob_clean(); } 

I also tried options like ob_start(false, 0, true); and ob_end_clean() , to no avail.

What am I missing?

+6
php output-buffering
source share
2 answers

you may need something like this

 <?php public function testSomething (){ ob_start(); ob_implicit_flush(false); // turn off implicit flush // Make your output below $class = new MyClass(); $class->method(); // End of output // store output into variable: $output = ob_get_contents(); } ?> 
+2
source share

Do you have implicit_flush set to true in your PHP ini? This can lead to the behavior that you see when it tells PHP to report that the output level is automatically turned off automatically after each output block. This is equivalent to calling the PHP function flush () after each call to print () or echo () and each block of HTML.

0
source share

All Articles