在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
简单 php 代码跟踪调试实现
debug_backtrace:生成回溯 debug_print_backtrace:打印回溯 1. debug_backtrace ($options = DEBUG_BACKTRACE_PROVIDE_OBJECT, $limit = 0) {}
$backtrace = debug_backtrace(); var_dump($backtrace);
<?php // 订单资料 class Order{ // 获取订单资料 function get_order($order_id){ $user_id = 1001; // 获取用户资料 $oUser = new User; $user_info = $oUser->get_user($user_id); // 订单资料 $order_info = array( 'order_id' => $order_id, 'order_name' => 'my order', 'user_info' => $user_info, ); return $order_info; } } class User{ // 获取用户资料 function get_user($user_id){ // 获取用户讯息 $oMessage = new Message; $user_message = $oMessage->get_message($user_id); $user_info = array( 'user_id' => $user_id, 'name' => 'fdipzone', 'message' => $user_message ); return $user_info; } } class Message{ // 获取用户讯息 function get_message($user_id){ $message = array( array('id'=>1, 'title'=>'message1'), array('id'=>2, 'title'=>'message2'), ); // 加入跟踪调试 $backtrace = debug_backtrace(); var_dump($backtrace); return $message; } } // 获取用户订单资料 $order_id = 1000000; $oOrder = new Order; $order_info = $oOrder->get_order($order_id); 结果:
2.打印回溯 debug_print_backtrace (int $options = 0,int $limit = 0) :
debug_print_backtrace(); 代码: <?php // 订单资料 class Order{ // 获取订单资料 function get_order($order_id){ $user_id = 1001; // 获取用户资料 $oUser = new User; $user_info = $oUser->get_user($user_id); // 订单资料 $order_info = array( 'order_id' => $order_id, 'order_name' => 'my order', 'user_info' => $user_info, ); return $order_info; } } class User{ // 获取用户资料 function get_user($user_id){ // 获取用户讯息 $oMessage = new Message; $user_message = $oMessage->get_message($user_id); $user_info = array( 'user_id' => $user_id, 'name' => 'fdipzone', 'message' => $user_message ); return $user_info; } } class Message{ // 获取用户讯息 function get_message($user_id){ $message = array( array('id'=>1, 'title'=>'message1'), array('id'=>2, 'title'=>'message2'), ); // 加入跟踪调试 //$backtrace = debug_backtrace(); //var_dump($backtrace);//fixme or debug_print_backtrace(); return $message; } } // 获取用户订单资料 $order_id = 1000000; $oOrder = new Order; $order_info = $oOrder->get_order($order_id); 结果: |
2022-07-18
2022-08-16
2022-11-06
2022-08-18
2022-08-15
请发表评论