Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP command line output buffer outputs regardless of buffer settings

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 suffice, but they aren't having an effect.

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

I've also tried variations such as ob_start(false, 0, true); and ob_end_clean() to no avail.

What am I missing?

like image 276
bcmcfc Avatar asked Mar 28 '11 15:03

bcmcfc


1 Answers

you may want 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();
}
?>
like image 192
thaolt Avatar answered Nov 15 '22 15:11

thaolt