PHPでWarningを非表示にする

PHPでWarningを非表示にする方法をメモ。

サンプルコード

存在しないファイルをincludeして、Warningを表示させてみます。

PHP

<?php
include "Warning.php";
?>

以下のような形でWarningが表示されました。

Warning: include(Warning.php): failed to open stream: No such file or directory in /xxx/sample/to-hide-the-warning-in-php/index.php on line 16
Warning: include(): Failed opening 'Warning.php' for inclusion in /xxx/sample/to-hide-the-warning-in-php/index.php on line 16

 

対応方法

error_reporting(0);を設定することでWarningを非表示にできます。

PHP

<?php
error_reporting(0);
include "Warning.php";
?>

error_reporting()関数はパラメータによって表示するエラーの種類を設定できます。
 

【参考サイト】

 

このエントリーをはてなブックマークに追加

関連記事

コメントを残す

メールアドレスが公開されることはありません。
* が付いている欄は必須項目です

CAPTCHA


コメントが承認されるまで時間がかかります。

2024年4月
 123456
78910111213
14151617181920
21222324252627
282930