Heim  >  Artikel  >  php教程  >  php Exception打印error trace 实例

php Exception打印error trace 实例

WBOY
WBOYOriginal
2016-05-25 16:44:24968Durchsuche

本文章来给各位同学介绍关于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;
}
?>


教程网址:

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

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn