本文章来给各位同学介绍关于php Exception打印error trace 实例,对于php的Exception,可以通过getTraceAsString获得错误,而对于error则应该如下:
- function x()
- $x = debug_backtrace();
-
- array_shift($x);
- $i = 0;
- $xstr = '';
- foreach ($trace as $x) {
-
- $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;
- }
|