PHP Error Explained - What does this error mean in PHP?
P粉436410586
P粉436410586 2023-08-20 19:36:42
0
1
417
<p><br /></p><h3>这是什么?</h3> <p>这是关于在编写PHP时可能遇到的警告、错误和通知的一系列答案,如果你不知道如何修复它们。这也是一个社区维基,所以每个人都被邀请参与到这个列表的添加和维护中。</p> <h3>为什么会有这个?</h3> <p>像“Headers already sent”或“Calling a member of a non-object”这样的问题经常在Stack Overflow上出现。这些问题的根本原因总是相同的。因此,对这些问题的答案通常会重复说明它们,然后展示给OP在他们特定情况下需要更改的行。这些答案对网站没有任何价值,因为它们只适用于OP的特定代码。其他遇到相同错误的用户无法轻松地从中阅读到解决方案,因为它们过于局限。这很遗憾,因为一旦你理解了根本原因,修复错误就很简单。因此,这个列表试图以一种通用的方式解释解决方案。</p> <h3>我应该在这里做什么?</h3> <p>如果你的问题被标记为这个问题的重复,请在下面找到你的错误信息并将修复方法应用到你的代码中。答案通常包含进一步的链接,以便在只有通用答案的情况下进行调查。</p> <p>如果你想做出贡献,请在每个答案中添加你的“最喜欢”的错误信息、警告或通知,以及它的简短描述(即使只是突出显示与其手册页面相关的术语)、可能的解决方法或调试方法,以及有价值的现有问题和答案的列表。同时,欢迎改进任何现有答案。</p> <h2>列表</h2> <ul> <li>什么也看不见。页面是空白的。(也称为<em>白屏死亡</em>)</li> <li>代码不运行/看起来我的PHP代码的部分被输出</li> <li>警告:无法修改头信息 - 头部已发送</li> <li>警告:mysql_fetch_array()期望参数1为资源,但给定的是布尔值,也就是说,警告:mysql_fetch_array()的参数不是有效的MySQL结果资源</li> <li>警告:<em>[function]</em>期望参数1为资源,但给定的是布尔值</li> <li>警告:<em>[function]</em>:无法打开流:<em>[reason]</em></li> <li>警告:open_basedir限制生效</li> <li>警告:除以零</li> <li>警告:非法字符串偏移量 'XXX'</li> <li>警告:count()的参数必须是数组或实现Countable接口的对象</li> <li>解析错误:语法错误,意外的 '['</li> <li>解析错误:语法错误,意外的T_XXX</li> <li>解析错误:语法错误,意外的T_ENCAPSED_AND_WHITESPACE</li> <li>解析错误:语法错误,意外的T_PAAMAYIM_NEKUDOTAYIM</li> <li>解析错误:语法错误,意外的'require_once'(T_REQUIRE_ONCE),期望函数(T_FUNCTION)</li> <li>解析错误:语法错误,意外的T_VARIABLE</li> <li>致命错误:分配的内存大小为XXX字节已用尽(尝试分配XXX字节)</li> <li>致命错误:超过了XX秒的最大执行时间</li> <li>致命错误:调用非对象或null的成员函数...</li> <li>致命错误:调用未定义的函数XXX</li> <li>致命错误:无法重新声明XXX</li> <li>致命错误:无法在写上下文中使用函数返回值</li> <li>致命错误:AAA::BBB()的声明必须与CCC::BBB()兼容</li> <li>AAA::BBB()的返回类型应与CCC::BBB()兼容,或者应使用#[ReturnTypeWillChange]属性</li> <li>致命错误:在非对象上下文中使用$this</li> <li>致命错误:无法将Closure类的对象转换为字符串</li> <li>致命错误:未定义的类常量</li> <li>致命错误:未捕获的TypeError:参数#n必须是类型x,给定的是y</li> <li>注意:数组转换为字符串(< PHP 8.0),或警告:数组转换为字符串(>= PHP 8.0)</li> <li>注意:尝试获取非对象属性的错误</li> <li>注意:未定义的变量或属性</li> <li>“注意:未定义的索引”,或“警告:未定义的数组键”</li> <li>注意:未定义的偏移XXX [参考]</li> <li>注意:未初始化的字符串偏移量:XXX</li> <li>注意:使用未定义的常量XXX - 假定'XXX' / 错误:未定义的常量XXX</li> <li>MySQL:您的SQL语法有误;请检查与您的MySQL服务器版本相对应的手册,以了解正确的语法使用方式...</li> <li>严格标准:非静态方法<em>[<class>::<method>]</em>不应该被静态调用</li> <li>警告:函数期望参数X为布尔值/字符串/整数</li> <li>HTTP错误500 - 内部服务器错误</li> <li>已弃用:使用花括号的数组和字符串偏移访问语法已被弃用</li> </ul> <p>另外,请参见:</p> <ul> <li>参考 - PHP中的这个符号代表什么?</li> </ul><p><br /></p>
P粉436410586
P粉436410586

reply all(1)
P粉497463473

Warning: Unable to modify header information - header information has already been sent

When your script attempts to send HTTP headers to the client, but there is already output before, this causes 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, as shown below:

<html>
    <?php session_start(); ?>
    <head><title>我的页面</title>
</html>
...

session_start()The function will try to send header information with the session cookie to the client. But when PHP writes the <html> element to the output stream, the header information has already been sent. You need to move session_start() to the front.

You can solve this problem by looking at the line before the code that triggered the warning, and check where the output is. Move any code that sends header information before this code.

An often overlooked piece of output is the newline character after PHP's closing tag ?>. Common practice is to omit ?> on the last line of the file. Again, another common cause of this warning is a space, newline, or invisible character before the opening <?php, causing the web server to send header information and the whitespace/newline character, so when PHP cannot submit any header information when it starts parsing.

If you have multiple <?php ... ?>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)

Also make sure you don't have any byte order marks in your code, e.g. the script is encoded as UTF-8 with BOM.

Related questions:

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!