这是关于在编写PHP代码时可能遇到的警告、错误和通知的一系列答案,如果你对如何修复它们一无所知,可以参考这个列表。这也是一个社区维基,所以每个人都可以参与其中,添加和维护这个列表。
像“Headers already sent”或“Calling a member of a non-object”这样的问题在Stack Overflow上经常出现。这些问题的根本原因总是相同的。因此,对这些问题的答案通常会重复解释并显示给OP在他们特定情况下需要更改的行。这些答案对网站没有任何价值,因为它们只适用于OP的特定代码。其他遇到相同错误的用户无法轻松地从中读取解决方案,因为它们过于局限。这是令人遗憾的,因为一旦你理解了根本原因,修复错误就是微不足道的。因此,这个列表试图以一种通用的方式解释解决方案。
如果你的问题被标记为这个问题的重复,请在下面找到你的错误信息并将修复方法应用到你的代码中。答案通常包含进一步的链接,以便在仅仅通过通用答案无法明确解决问题时进行调查。
如果你想贡献,请在每个答案中添加你“最喜欢”的错误信息、警告或通知,以及它的简短描述(即使只是突出显示与它们手册页面相关的术语)、可能的解决方案或调试方法,以及有价值的现有Q&A的列表。同时,欢迎改进任何现有答案。
警告:mysql_fetch_array():提供的参数不是有效的MySQL结果资源
另外,请参见:
Warning: Unable to modify header information - header has been sent
When your script attempts to send HTTP headers to the client, but there is already output before, causing the headers to have already been sent to the client.
This is an
E_WARNING
, which does not stop the execution of the script.A typical example is a template file like this:
session_start()
The function will try to send a header with the session cookie to the client. But when PHP writes theelement to the output stream, the header has already been sent. You need to move
session_start()
to the top.You can resolve this issue by examining the line of code before the code that triggered the warning, and seeing where the output is. Move any code that sends headers before this code.
An often overlooked piece of output is the newline character after the PHP closing tag
?>
. It is generally considered standard practice to omit?>
when it is the last item in the file. Again, another common cause of this warning is that there is a space, newline, or invisible character before the opening, causing the web server to send the header and the whitespace/newline character, so when PHP No headers could be submitted when starting parsing.
If you have multiple
code blocks in your file, make sure there aren't any spaces between them. (Note: If you have auto-generated code, there may be multiple code blocks)
Please also make sure there are no Byte Order Marks in your code, for example the script is encoded as UTF-8 with BOM.
Related questions: