【发布时间】:2018-03-30 15:08:04
【问题描述】:
这是什么?
这是一些关于您在编写 PHP 时可能遇到的警告、错误和通知的答案,但不知道如何修复它们。这也是一个社区 Wiki,因此邀请所有人参与添加和维护此列表。
这是为什么?
像"Headers already sent" 或"Calling a member of a non-object" 这样的问题经常在 Stack Overflow 上弹出。这些问题的根本原因总是相同的。因此,这些问题的答案通常会重复它们,然后向 OP 显示在其特定情况下要更改哪一行。这些答案不会为站点增加任何价值,因为它们仅适用于 OP 的特定代码。其他具有相同错误的用户无法轻松地从中读取解决方案,因为他们过于本地化。这很可悲,因为一旦您了解了根本原因,修复错误就变得微不足道了。因此,此列表试图以通用的方式解释解决方案。
我应该在这里做什么?
如果您的问题已被标记为与此问题重复,请在下方找到您的错误消息并将修复应用于您的代码。答案通常包含进一步调查的链接,以防仅从一般答案中不清楚。
如果您想做出贡献,请添加您“最喜欢的”错误消息、警告或通知、每个答案一个、简短说明其含义(即使它只是在其手册页中突出显示术语)、可能的解决方案或调试方法和有价值的现有问答列表。此外,请随时改进任何现有答案。
名单
- Nothing is seen. The page is empty and white.(也称为白页/死亡屏幕)
- Code doesn't run/what looks like parts of my PHP code are output
- Warning: Cannot modify header information - headers already sent
-
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given 又名
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource - Warning: [function] expects parameter 1 to be resource, boolean given
- Warning: [function]: failed to open stream: [reason]
- Warning: open_basedir restriction in effect
- Warning: Division by zero
- Warning: Illegal string offset 'XXX'
- Warning: count(): Parameter must be an array or an object that implements Countable
- Parse error: syntax error, unexpected '['
- Parse error: syntax error, unexpected T_XXX
- Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE
- Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM
- Parse error: syntax error, unexpected 'require_once' (T_REQUIRE_ONCE), expecting function (T_FUNCTION)
- Parse error: syntax error, unexpected T_VARIABLE
- Fatal error: Allowed memory size of XXX bytes exhausted (tried to allocate XXX bytes)
- Fatal error: Call to a member function ... on a non-object or null
- Fatal Error: Call to Undefined function XXX
- Fatal Error: Cannot redeclare XXX
- Fatal error: Can't use function return value in write context
- Fatal error: Declaration of AAA::BBB() must be compatible with that of CCC::BBB()'
- Return type of AAA::BBB() should either be compatible with CCC::BBB(), or the #[\ReturnTypeWillChange] attribute should be used
- Fatal error: Using $this when not in object context
- Fatal error: Object of class Closure could not be converted to string
- Fatal error: Undefined class constant
- Fatal error: Uncaught TypeError: Argument #n must be of type x, y given
- Notice: Array to string conversion
- Notice: Trying to get property of non-object error
- Notice: Undefined variable or property
- "Notice: Undefined Index", or "Warning: Undefined array key"
- Notice: Undefined offset XXX【参考】
- Notice: Uninitialized string offset: XXX
- Notice: Use of undefined constant XXX - assumed 'XXX'
- MySQL: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ... at line ...
- Strict Standards: Non-static method [<class>::<method>] should not be called statically
- Warning: function expects parameter X to be boolean/string/integer
- HTTP Error 500 - Internal server error
- Deprecated: Arrays and strings offset access syntax with curly braces is deprecated
另见:
【问题讨论】:
-
另外,要将讨论移出 cmets,请转到 this 元问题
标签: php debugging error-handling warnings custom-error-handling