「通知」の簡単な修正: そのインデックスが存在するかどうかを確認するだけです。したがって、このコードは次のとおりです。
$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.ini
PHP エラー レベル定数の完全なリストは、そのファイルにあるはずです。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