对比才发现getTrace要比getTraceAsString清晰得多的多class A{
public function excetionTest($params){
throw new Exception("xxx");
}
}
class B{
public function test($params){
$a = new A();
$a->excetionTest([1,2,3]);
}
}
try{
$b = new B();
$b->test("test");
}catch(Exception $e){
var_export($e->getTrace());
echo "\n";
var_export($e->getTraceAsString());
echo "\n";
}
输出结果// getTrace
array (
0 =>
array (
'file' => '/Users/zhoumengkang/Downloads/xxx.php',
'line' => 11,
'function' => 'excetionTest',
'class' => 'A',
'type' => '->',
'args' =>
array (
0 =>
array (
0 => 1,
1 => 2,
2 => 3,
),
),
),
1 =>
array (
'file' => '/Users/zhoumengkang/Downloads/xxx.php',
'line' => 19,
'function' => 'test',
'class' => 'B',
'type' => '->',
'args' =>
array (
0 => 'test',
),
),
)
// getTraceAsString
#0 /Users/zhoumengkang/Downloads/xxx.php(11): A->excetionTest(Array)
#1 /Users/zhoumengkang/Downloads/xxx.php(19): B->test(\'test\')
#2 {main}