教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 php Exception打印error trace 实例

php Exception打印error trace 实例

发布时间:2016-10-26   编辑:jiaochengji.com
教程集为您提供php Exception打印error trace 实例等资源,欢迎您收藏本站,我们将为您提供最新的php Exception打印error trace 实例资源
本文章来给各位同学介绍关于php Exception打印error trace 实例,有需要的朋友可进入参考。


对于php的Exception,可以通过getTraceAsString获得错误栈。


而对于error则应该如下:

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy3013')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy3013>

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

 return $xstr;
}

您可能感兴趣的文章:
php Exception打印error trace 实例
关于PHP中Exception、Error Handler的细节以及实例详解
php 异常处理try catch Exceptions
php的异常处理基础方法
CodeIgniter3.0 框架自定义异常处理的方法介绍
php soap客户端调试实例
php拦截异常怎么写
php调试利器:FirePHP的安装与使用
PHP 错误捕捉处理 Exception
PHP7.1和7.2 新增功能详解

[关闭]
~ ~