致命与非致命错误的PHP? [英] fatal vs. not fatal error in php?

查看:137
本文介绍了致命与非致命错误的PHP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道哪些错误是致命错误,而不是PHP错误(尽管也对其他语言感兴趣)。是否有每种错误类型的简要说明和/或清单?



我想知道的原因是因为有时当我使PHP错误时,我的 $会有意义吗?



_SESSION (实际上使用codeigniter会话)被破坏了,而在其他情况下却没有,我不能完全理解为什么会发生这种情况。

解决方案

好吧,命名很不言自明:



致命错误是严重错误这意味着解析器可能由于该错误而无法继续解析代码的其余部分。例如:




  • 您的网络服务器内存不足,无法解析脚本(例如,解析器命中了 memory_limit 在php.ini中设置)。

  • 该脚本包含无限循环(例如 while(1){echo Hi friends!;} 并比php.ini中设置的 max_execution_time 运行更长的时间。



非致命错误通常称为警告,它们仍然很严重,应予以修复,但不会造成错误解析器停止解析您的代码,无论发生了什么错误,它仍然可以继续。例如:




  • 您正在调用未设置的变量。

  • 您正在请求数组中的键那不存在。

  • 您正在调用一个不存在的函数。



希望这样做为您整理一些东西。


I'm wondering what errors are considered fatal vs. not in PHP (though interested in other languages too). Is there a concise explanation and/or listing of each somewhere of error types? Does using the expression "non-fatal" even make sense?

The reason I'm wondering is because sometimes when I make PHP errors my $_SESSION (actually using codeigniter sessions) is destroyed whereas in other cases it is not and I can't quite put my finger on why this is happening.

解决方案

Well, the naming is pretty self-explanatory:

Fatal errors are critical errors and it means that the parser cannot possibly continue to parse the rest of your code, because of this error. For example:

  • Your webserver has run out of memory to parse the script (e.g. parser hit the memory_limit set in php.ini).
  • The script contains an infinite loop (e.g. while(1) { echo "Hi friend!"; } and runs longer than the set max_execution_time in your php.ini).

Non-fatal errors are usually called Warnings, they are still pretty serious and should be fixed, but do not cause the parser to stop parsing your code, it can still continue, regardless of the error that occurred. For example:

  • You are calling unset variables.
  • You are requesting a key in an array that does not exist.
  • You are calling an non-existing function.

Hope this clears things up a bit for you.

这篇关于致命与非致命错误的PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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