Home > php教程 > php手册 > php Exception打印error trace 实例

php Exception打印error trace 实例

WBOY
Release: 2016-05-25 16:44:24
Original
1029 people have browsed it

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


教程网址:

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template