首頁  >  文章  >  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