在输出缓冲区中如何看到包含的文件中的php错误? [英] How to see php error in included file while output buffer?

查看:154
本文介绍了在输出缓冲区中如何看到包含的文件中的php错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用输出缓冲区时的空白屏幕,并且包含的​​文件中有语法错误。

PHP不会从输出缓冲区显示错误。

如何查看php输出缓冲区语法错误?



在我的项目中,如果文件不存在,我使用 @ 来隐藏错误。但是如果文件确实存在并且有致命错误,它们将不会被显示。



这里是代码示例。



< pre class =lang-php prettyprint-override> <?php
$ title ='Some title';

ob_start();

@include('body.tpl'); //我有一些PHP在这里

$ content = ob_get_clean();


?><!doctype html>
< html lang =en>
< head>
< meta charset =UTF-8>
< title><?= $ title; ?>< /标题>
< / head>
< body>
<?= $ content; ?>
< / body>
< / html>


解决方案

一个选项是覆盖错误处理程序,并调用ob_end ();之前打印出来抛出错误/警告/异常。
其他选项,是经常检查错误日志,如果遇到奇怪的行为。


Blank screen when using output buffer and there's syntax errors in included file.
PHP doesn't show errors from output buffer.
How to see php output buffer syntax errors?

In my project I used @ for hiding errors if file doesn't exist. But if file does exist and has fatal errors, they would not been shown as well.

Here's code example.

<?php
$title = 'Some title';

ob_start();

@include ('body.tpl'); //I have some php here

$content = ob_get_clean();


?><!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title><?= $title; ?></title>
</head>
<body>
    <?= $content; ?>
</body>
</html>

解决方案

One option is to override error handlers, and call ob_end(); before printing out thrown error/warning/exception. Other option, is to frequently check error log, if you encounter odd behaviour.

这篇关于在输出缓冲区中如何看到包含的文件中的php错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆