PHP 是一种广泛使用的服务器端脚本语言,它在开发过程中可能会遇到各种错误。PHP 错误通常分为几个主要类别,每种错误都有其特定的提示内容。以下是常见的 PHP 错误类型及其提示内容:
Parse error: syntax error, unexpected '...' in ... on line ...
Fatal error: Uncaught Error: Call to undefined function ... in ... on line ...
Warning: include(): Failed opening '...' for inclusion (include_path='...') in ... on line ...
Notice: Undefined variable: ... in ... on line ...
isset()
函数检查变量是否存在。Strict Standards: Non-static method ... should not be called statically in ... on line ...
Deprecated: Function ... is deprecated in ... on line ...
Fatal error: Allowed memory size of ... bytes exhausted (tried to allocate ... bytes) in ... on line ...
memory_limit
配置值,或优化代码减少内存使用。Fatal error: Maximum execution time of ... seconds exceeded in ... on line ...
max_execution_time
配置值,或优化代码减少执行时间。Warning: mysqli_connect(): (HY000/2002): Connection refused in ... on line ...
Warning: file_get_contents(...): failed to open stream: No such file or directory in ... on line ...
TypeError: Argument ... passed to ... must be of the type ..., ... given in ... on line ...
Fatal error: Uncaught Exception: ... in ... on line ...
try-catch
块捕获并处理异常。Notice: Use of undefined constant ... - assumed '...' in ... on line ...
Notice: Undefined index: ... in ... on line ...
isset()
函数检查。Notice: Undefined offset: ... in ... on line ...
isset()
函数检查。Notice: Undefined property: ...::$... in ... on line ...
Fatal error: Call to undefined method ...::...() in ... on line ...
Fatal error: Class '...' not found in ... on line ...
Fatal error: Class '...' not found in ... on line ...
Fatal error: Call to undefined function ...() in ... on line ...
Notice: Undefined variable: ... in ... on line ...
isset()
函数检查。Notice: Use of undefined constant ... - assumed '...' in ... on line ...
Notice: Undefined index: ... in ... on line ...
isset()
函数检查。Notice: Undefined offset: ... in ... on line ...
isset()
函数检查。Notice: Undefined property: ...::$... in ... on line ...
Fatal error: Call to undefined method ...::...() in ... on line ...
Fatal error: Class '...' not found in ... on line ...
Fatal error: Class '...' not found in ... on line ...
Fatal error: Call to undefined function ...() in ... on line ...
Notice: Undefined variable: ... in ... on line ...
isset()
函数检查。Notice: Use of undefined constant ... - assumed '...' in ... on line ...
Notice: Undefined index: ... in ... on line ...
isset()
函数检查。Notice: Undefined offset: ... in ... on line ...
isset()
函数检查。Notice: Undefined property: ...::$... in ... on line ...
Fatal error: Call to undefined method ...::...() in ... on line ...
Fatal error: Class '...' not found in ... on line ...
Fatal error: Class '...' not found in ... on line ...
Fatal error: Call to undefined function ...() in ... on line ...
Notice: Undefined variable: ... in ... on line ...
isset()
函数检查。Notice: Use of undefined constant ... - assumed '...' in ... on line ...
Notice: Undefined index: ... in ... on line ...
isset()
函数检查。Notice: Undefined offset: ... in ... on line ...
isset()
函数检查。Notice: Undefined property: ...::$... in ... on line ...
Fatal error: Call to undefined method ...::...() in ... on line ...
Fatal error: Class '...' not found in ... on line ...
Fatal error: Class '...' not found in ... on line ...
Fatal error: Call to undefined function ...() in ... on line ...
Notice: Undefined variable: ... in ... on line ...
isset()
函数检查。Notice: Use of undefined constant ... - assumed '...' in ... on line ...
Notice: Undefined index: ... in ... on line ...
isset()
函数检查。Notice: Undefined offset: ... in ... on line ...
isset()
函数检查。Notice: Undefined property: ...::$... in ... on line ...
Fatal error: Call to undefined method ...::...() in ... on line ...
Fatal error: Class '...' not found in ... on line ...
Fatal error: Class '...' not found in ... on line ...
Fatal error: Call to undefined function ...() in ... on line ...
Notice: Undefined variable: ... in ... on line ...
isset()
函数检查。Notice: Use of undefined constant ... - assumed '...' in ... on line ...
Notice: Undefined index: ... in ... on line ...