所以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.
我做错了什么,有解决方案吗?
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。