【发布时间】:2015-09-20 21:20:54
【问题描述】:
让我们假设一个简单的 sn-p 用于模板并且是using output control (ob)
public function capture($file, array $args = array())
{
extract($args, EXTR_SKIP);
ob_start();
require $file; //'foo.php'
return ob_get_clean();
}
而foo.php 有错误(由error handler 和shutdown handler 处理)
<?php
echo "before";
echo $someVariable; //$someVariable is undefined here
echo "after";
输出
before <- would like to avoid
some message from the error handler
问题:是否有可能避免文件出错时的任何输出?
是的,
-
我阅读/分析了一些类似的问题,但没有一个给我一个明确的答案,无论是不是。
Errors inside of output buffer
How to see php error in included file while output buffer?(@marc-b - 可能不是)
我知道您不应该在自己的代码中处理此类错误,因为它必须经过干净和测试,但您仍然可能会遇到一些错误,例如错字、未定义的变量等。
【问题讨论】:
-
你能不能只使用 ob_get_clean(),我在生产中使用它来避免出现在屏幕上的错误
标签: php error-handling output output-buffering