【发布时间】:2015-05-09 16:00:12
【问题描述】:
可以像下面这样在 php 中进行错误处理吗?我对ob_start()/ob_clean()/ob_flush()不是很熟悉,所以我想知道使用它们有什么不好的影响吗?例如,它们会影响性能吗?
<?php
function custorErr()
{
ob_clean();
//echo error message and some other error handling...
die();
}
set_error_handler("custorErr");
ob_start();
?>
<!doctype html>
<!-- html here -->
<html>
<head>
</head>
<body>
demo
</body>
</html>
<?php ob_flush();?>
如果这不是最佳做法,那么有没有更好的方法在出现错误时清除所有页面内容?
【问题讨论】:
-
我实际上并不确定这一点。好问题!但我想在使用 ob_start() 之前放置 set_error_handler 是个好主意
-
@bestprogrammerintheworld 我按照你的建议编辑了这个问题中的代码
标签: php error-handling