29
27

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 5 years have passed since last update.

PHP で Backtrace を出力する

Posted at

PHP は標準ではエラーを出力した際に、Stacktrace (PHP では Backtrace と言うようだ) を出力してくれない。

下記のようなコードをエラー発生箇所の直前に入れることで、当該のエラーがどのような経路で発生しているのか辿ることができる。

$trace = debug_backtrace();
foreach($trace as $line) {
    error_log("{$line["file"]}: line {$line["line"]}");
}

debug_backtrace() が返す配列をそのまま print_r しても良いが、情報が多すぎて読みづらいので、上記のように値を抽出した方が良いと思う。

29
27
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
29
27

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?