ホームページ  >  記事  >  php教程  >  php Exception打印error trace 实例

php Exception打印error trace 实例

WBOY
WBOYオリジナル
2016-05-25 16:44:24968ブラウズ

本文章来给各位同学介绍关于php Exception打印error trace 实例,对于php的Exception,可以通过getTraceAsString获得错误,而对于error则应该如下:

<?php
function x() $x = debug_backtrace();
//remove stack of this function
array_shift($x);
$i = 0;
$xstr = &#39;&#39;;
foreach ($trace as $x) {
    //TODO need check exists args
    $args = $x[&#39;args&#39;];
    if (!$args) {
        $argstr = &#39;&#39;;
    } else {
        $argstr = &#39;&#39;;
        $first = true;
        foreach ($args as $arg) {
            if (!$first) {
                $argstr.= &#39;,&#39;;
            }
            $first = false;
            if (is_object($arg)) {
                $argstr.= &#39;Object[&#39; . get_class($arg) . &#39;]&#39;;
            } elseif (is_array($arg)) {
                $argstr.= &#39;Array&#39;;
            } else {
                $argstr.= $arg;
            }
        }
    }
    $xstr.= "[#$i] {$x[&#39;file&#39;]}({$x[&#39;line&#39;]}) {$x[&#39;function&#39;]} ($argstr)" . PHP_EOL;
    $i++;
}
return $xstr;
}
?>


教程网址:

欢迎收藏∩_∩但请保留本文链接。

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。