>  기사  >  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으로 문의하세요.