PHP强大包括处理错误?
I have a PHP app "index.php" that, for various reasons, needs to run other PHP scripts by using include_once
on that other script. That other script isn't very stable, so is there some way to do a safe include_once
that won't halt the caller?
我有一个PHP应用程序“index.php”,由于各种原因,需要通过在其他脚本上使用include_once来运行其他PHP脚本。那个其他脚本不是很稳定,那么有没有办法做一个不会停止调用者的安全include_once?
i.e.:
<?php
safely_include_once('badfile.php'); // MAY throw syntax error, parse error, other badness
echo "I can continue execution after error";
?>
(I know what a bad idea this can be, etc., rest assured this isn't production-environment stuff.)
(我知道这可能是个坏主意,等等,请放心,这不是生产环境的东西。)
8 个解决方案
#1
6
You can just
你可以
@include "fileWithBadSyntax.php";
Which, from my quick tests, works for both parse errors or errors thrown with trigger_error().
从我的快速测试中,它适用于解析错误或使用trigger_error()抛出的错误。
EDIT: This is completely wrong. See sneak's answer, which is correct, if somewhat unhelpful.
编辑:这是完全错误的。看看潜行的答案,这是正确的,如果有点无益的话。
更多相关文章
- PHP基础之脚本传参
- phpBB3导入帖子的Python脚本
- 您是否认为PHP中的错误形式是在类方法中访问超级全局变量?
- 解析错误:语法错误,第12行/home/public_html/gigs.html中的意外T_L
- PHP脚本在我的Wordpress文件中。请解码或帮助我删除它。
- eclipse 编写php错误
- 我无法定义我的错误
- php中的错误级别
- fgetcsv()错误地将双引号添加到第一行的第一个元素