fatal vs. not fatal error in php?

北战南征 提交于 2019-12-24 00:53:08

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/10495098/fatal-vs-not-fatal-error-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!