Debug_backtrace () is a very low-key function, very few people pay attention to it, this article mainly introduces the use of debugging function Debug_backtrace in PHP, the article through the sample code introduced in very detailed, For everyone's study or work has a certain reference learning value, interested friends to study together.
Objective
What if we want to know who called a method? Debug_backtrace can be solved. Debug_backtrace () can print out the calling process for a page, from where to where to go to a glance.
Sometimes we want to know the call stack of this function or method, that is, how it is called at the first level, and can be printed with PHP's Debug_backtrace function, like this:
Sample code
Public Function Update (Request $request, $id) {DD (Debug_backtrace ())), $getGameID = function ($request) {if (! $request-> ; game_id) {return + intval ($request->id);} return $request->game_id; }; $previews = $this->getgamepreviews ($request->game_preview); $request->merge ([' Game_preview ' = Json_encode ($previews), ' game_id ' + $getGameID ($request)]); Egretgame::where (' id ', $id)->update ($request->except ([' _token ', ' _method ']); Return Redirect ()->route (' Egretgame.index ')->with (' Success ', ' Edit succeeded! ');}
You can control the number of stack levels that need to backtrack, where the first parameter of Debug_backtrace is a constant DEBUG_BACKTRACE_PROVIDE_OBJECT , indicating the information that displays the object, and the second parameter is used to control the number of backtracking stacks, which is all by default.
effect, call hierarchy relationship at a glance:
PHP Official Document: http://php.net/manual/zh/function.debug-backtrace.php