“通知”的简单修复:只需检查该索引是否存在。所以这段代码:
$commentator_name = $comment_array[$i];
$commentator_comment = $comment_array[$i+1];
对此的更改:
$commentator_name = $commentator_comment = '';
if (isset($comment_array[$i])) {
$commentator_name = $comment_array[$i];
}
if (isset($comment_array[$i+1])) {
$commentator_comment = $comment_array[$i+1];
}
当我编写这段代码时,我在一台旧笔记本电脑上工作,我不得不在服务器上工作,因为 WAMP 等没有工作,当时我没有收到通知。
可能是新服务器设置与旧服务器设置之间的错误报告级别。这意味着新服务器设置为报告 PHP 通知,但旧服务器没有。
要调整错误报告的设置,您可以先进入您php.ini
的线路并寻找error_reporting
线路。在 Ubuntu 12.04 和其他 Linux 安装上,php.ini
位于此处:
/etc/php5/apache2/php.ini
通常,该行只是设置为E_ALL
如下所示:
error_reporting = E_ALL
要禁用通知,您可以将该行调整为:
error_reporting = E_ALL & ~E_NOTICE
您甚至可以通过将它们链接到该行的末尾来添加更多要禁用的选项,如下所示:
error_reporting = E_ALL & ~E_NOTICE & ~E_WARNING
PHP 错误级别常量的完整列表应该在该php.ini
文件中。如果在典型php.ini
文件的注释中显示的副本,则为以下副本:
; Error Level Constants:
; E_ALL - All errors and warnings (includes E_STRICT as of PHP 6.0.0)
; E_ERROR - fatal run-time errors
; E_RECOVERABLE_ERROR - almost fatal run-time errors
; E_WARNING - run-time warnings (non-fatal errors)
; E_PARSE - compile-time parse errors
; E_NOTICE - run-time notices (these are warnings which often result
; from a bug in your code, but it's possible that it was
; intentional (e.g., using an uninitialized variable and
; relying on the fact it's automatically initialized to an
; empty string)
; E_STRICT - run-time notices, enable to have PHP suggest changes
; to your code which will ensure the best interoperability
; and forward compatibility of your code
; E_CORE_ERROR - fatal errors that occur during PHP's initial startup
; E_CORE_WARNING - warnings (non-fatal errors) that occur during PHP's
; initial startup
; E_COMPILE_ERROR - fatal compile-time errors
; E_COMPILE_WARNING - compile-time warnings (non-fatal errors)
; E_USER_ERROR - user-generated error message
; E_USER_WARNING - user-generated warning message
; E_USER_NOTICE - user-generated notice message
; E_DEPRECATED - warn about code that will not work in future versions
; of PHP
; E_USER_DEPRECATED - user-generated deprecation warnings