そのため、 、、 のob_start()
ように別のバッファ関数が呼び出されるまで、出力をキャプチャすることになっています。ob_get_clean()
ob_get_contents()
ob_get_flush()
ただし、バッファー リーダー内で例外がスローされると、リーダーを停止し、出力をキャプチャし続ける代わりにエコーすることで、リーダーに影響を与えます。これは私が防ぎたいものです。
これが私のスクリプトだとしましょう:
<?php
error_reporting(0);
try {
ob_start();
echo "I don't wanna output this what so ever, so want to cache it in a variable with using ob_ functions";
$unlink = unlink('some file that does not exist');
if(!$unlink) throw new Exception('Something really bad happen.', E_ERROR); //throwing this exception will effect the buffer
$output = ob_get_clean();
} catch(Exception $e) {
echo "<br />Some error occured: " . $e->getMessage();
//print_r($e);
}
?>
このスクリプトは次を出力します。
I don't wanna output this what so ever, so want to cache it in a variable with using ob_ functions
Some error occurred: Something really bad happen.
印刷するだけの場合
Some error occurred: Something really bad happen.
私は何を間違っていますか、解決策はありますか?