4

I have the following code:

function a(){ die( 'some text' ) }
ob_start();
a();
$return = ob_get_clean();
echo 'result:'
var_dump( $return );

and it doesn't work.

I get some text in my browser.

How can I make it work? How can I catch die() in a buffered function?

PS: I cannot change the function.

What should I use instead of ob_start() ?

I tried to run the following code:

register_shutdown_function( function() {
    $message = ob_get_contents(); //Capture 'Doh'
    ob_end_clean(); //Cleans output buffer
} );
ob_start();
die( 'works' );
ob_end_clean();

and it didn't work...

Berry M.
  • 469
  • 1
  • 4
  • 17
Maikal
  • 247
  • 2
  • 11
  • Why are you surprised? ob_start turns on output buffering. Your script dies before getting the buffer contents and printing it. – user4035 Aug 05 '15 at 20:43
  • 2
    *Terminates execution of the script* <- You can't catch it – Rizier123 Aug 05 '15 at 20:44
  • 3
    possible duplicate of [Can I catch exit() and die() messages?](http://stackoverflow.com/questions/3836524/can-i-catch-exit-and-die-messages) – user4035 Aug 05 '15 at 20:45

0 Answers0