PHP Notice 错误现象与原因分析
在 E:\Server\vhosts\www.lvtao.net\global.php 的第 50 行出现了 Notice: Use of undefined constant ALL_PS - assumed 'ALL_PS' 的提示信息。
在 E:\Server\vhosts\www.lvtao.net\libs\template.core.php 的第 51 行显示 Notice: Undefined index: EaseTemplateVer 的错误提示。
在 E:\Server\vhosts\www.lvtao.net\global.php 的第 54 行触发了 Notice: Use of undefined constant uid - assumed 'uid' 的警告。
在 E:\Server\vhosts\www.lvtao.net\global.php 的第 54 行同时出现了 Notice: Undefined index: uid 的提示内容。
在 E:\Server\vhosts\www.lvtao.net\global.php 的第 55 行报告了 Notice: Use of undefined constant cuid - assumed 'cuid' 的信息。
在 E:\Server\vhosts\www.lvtao.net\global.php 的第 55 行还伴随有 Notice: Undefined index: cuid 的提示。
在 E:\Server\vhosts\www.lvtao.net\global.php 的第 56 行检测到 Notice: Use of undefined constant shell - assumed 'shell' 的警告。
在 E:\Server\vhosts\www.lvtao.net\global.php 的第 56 行同样显示了 Notice: Undefined index: shell 的内容。
在 E:\Server\vhosts\www.lvtao.net\global.php 的第 57 行引发了 Notice: Use of undefined constant cshell - assumed 'cshell' 的提示。
在 E:\Server\vhosts\www.lvtao.net\global.php 的第 57 行也出现了 Notice: Undefined index: cshell 的信息。
在 E:\Server\vhosts\www.lvtao.net\global.php 的第 58 行报出 Notice: Use of undefined constant username - assumed 'username' 的警告。
在 E:\Server\vhosts\www.lvtao.net\global.php 的第 58 行同时存在 Notice: Undefined index: username 的提示。
在 E:\Server\vhosts\www.lvtao.net\global.php 的第 59 行触发了 Notice: Use of undefined constant cusername - assumed 'cusername' 的信息。
在 E:\Server\vhosts\www.lvtao.net\global.php 的第 59 行还伴有 Notice: Undefined index: cusername 的提示内容。
在 E:\Server\vhosts\www.lvtao.net\companyjob.php 的第 10 行显示了 Notice: Use of undefined constant id - assumed 'id' 的警告。
在 E:\Server\vhosts\www.lvtao.net\companyjob.php 的第 14 行再次出现 Notice: Use of undefined constant id - assumed 'id' 的提示。
在 E:\Server\vhosts\www.lvtao.net\companyjob.php 的第 16 行报告了 Notice: Use of undefined constant content - assumed 'content' 的信息。
在 E:\Server\vhosts\www.lvtao.net\companyjob.php 的第 16 行又一次出现了 Notice: Use of undefined constant content - assumed 'content' 的警告。
在 E:\Server\vhosts\www.lvtao.net\companyjob.php 的第 17 行触发了 Notice: Use of undefined constant description - assumed 'description' 的提示。
在 E:\Server\vhosts\www.lvtao.net\companyjob.php 的第 17 行同样显示了 Notice: Use of undefined constant description - assumed 'description' 的内容。
在 E:\Server\vhosts\www.lvtao.net\companyjob.php 的第 18 行报出 Notice: Use of undefined constant provinceid - assumed 'provinceid' 的警告。
在 E:\Server\vhosts\www.lvtao.net\companyjob.php 的第 19 行出现了 Notice: Use of undefined constant cityid - assumed 'cityid' 的提示。
在 E:\Server\vhosts\www.lvtao.net\companyjob.php 的第 20 行检测到 Notice: Use of undefined constant hy - assumed 'hy' 的信息。
在 E:\Server\vhosts\www.lvtao.net\libs\template.core.php 的第 557 行报告了 Notice: Undefined variable: content 的错误。
进入网站后会出现大量类似的提示消息,但程序可以正常显示页面并运行。
例如在 d:\ctb1.5\ctb\include\config.php 的第 23 行也会出现 Notice: Use of undefined constant ctbTitle - assumed 'ctbTitle' 等类似提示。
这些现象属于 PHP 的提示而非严重报错,因为 PHP 允许直接使用未事先声明的变量,仅会给出提示。正式网站通常会关闭此类提示,甚至关闭所有错误信息显示。
以下是关闭 PHP 提示的具体方法。
首先需要搜索 php.ini 配置文件。
找到 error_reporting = E_ALL 这一行设置。
将其修改为以下代码:
error_reporting = E_ALL & ~E_NOTICE
此外还有一种非标准但有效的替代方案。
可以在每个 PHP 文件的头部添加代码。
加入 error_reporting(0); 虽然操作较为繁琐,但能有效解决问题。