5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

PHPスクリプトで発生したエラーがどの出力レベルで報告されるのかを確認するスクリプト

Last updated at Posted at 2020-12-02

この記事は,PHP Advent Calendar 2020 3日目の記事として公開される予定です(11月23日記載).

今年のカレンダーは @rana_kualu さんが作成してくれました.ありがとうございました.

本題

phpのスクリプトで発生したエラーについて,そのエラーがどの出力レベルで報告されるかを確認するスクリプトです.

error_reporting.sh
#!/bin/bash

SCRIPT_NAME="$1"

LEVELS=(E_ERROR E_WARNING E_PARSE E_NOTICE E_CORE_ERROR E_CORE_WARNING E_COMPILE_ERROR E_COMPILE_WARNING E_USER_ERROR E_USER_WARNING E_USER_NOTICE E_STRICT E_RECOVERABLE_ERROR E_DEPRECATED E_USER_DEPRECATED)

for LEVEL in ${LEVELS[@]};
do
  echo "${LEVEL}"
  php -d error_reporting=${LEVEL} "$1"
done

実行結果はこんな感じです.

$ . ./error_reporting.sh e_notice.php 
E_ERROR
E_WARNING
E_PARSE
E_NOTICE
PHP Notice:  Undefined variable: a in /home/taro/projects/php-fun/e_notice.php on line 4
PHP Stack trace:
PHP   1. {main}() /home/taro/projects/php-fun/e_notice.php:0
E_CORE_ERROR
E_CORE_WARNING
E_COMPILE_ERROR
E_COMPILE_WARNING
E_USER_ERROR
E_USER_WARNING
E_USER_NOTICE
E_STRICT
E_RECOVERABLE_ERROR
E_DEPRECATED
E_USER_DEPRECATED

読み込んだファイルです.

e_notice.php
<?php

echo $a;

以上 PHP Advent Calendar 2020 3日目でした.

明日は @yoshikyoto さんです.

参考・関連

5
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?