3v4l.org

run code in 500+ PHP versions simultaneously
<?php function debug($msg){ fwrite(STDOUT, sprintf("[Debug] %s\n", $msg)); } // capture any unexpected output and exit execution ob_start(function($buffer, $phase){ // prevent exit on ob_end_*() if(($phase & PHP_OUTPUT_HANDLER_FINAL) === 0){ $f = new class ($buffer) { public function __construct(private $buffer) {} public function __destruct() { debug('exit call'); exit(); // or // throw new UnexpectedOutputException($this->buffer); } }; } debug(sprintf("callback called, buffer: %s, type: %d", var_export($buffer, true), $phase)); // prevent buffer call return null; }, 1); // do some work on shutdown register_shutdown_function(function() { debug('ob_end_clean'); ob_end_clean(); debug('shutting down'); }); debug('echo x1'); echo 'x1'; debug('echo x2'); echo 'x2';

preferences:
23.12 ms | 483 KiB | 5 Q