Home > Article > Backend Development > Detailed explanation of the use of debug_backtrace debugging function in php
debug_backtrace() is a very low-key function, and few people have paid attention to it. This article mainly introduces you to the use of the debug function debug_backtrace in PHP. The article introduces it in detail through example code, which is very helpful to everyone. Studying or working has certain reference learning value. Friends who are interested should follow the editor to learn together.
Preface
If we want to know who called a certain method? debug_backtrace can solve it. debug_backtrace() can print out the calling process of a page, where it comes from and where it goes. Sometimes we want to know the call stack of this function or method, that is, how it is called level by level. If you arrive, you can use PHP's debug_backtrace function to print it, like this:
Sample code
public function update(Request $request, $id) { dd(debug_backtrace()); $getGameID = function ($request) { if (!$request->game_id) { return 1000 + 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', '编辑成功!'); }
, which indicates that the information of this object is displayed. The second parameter is used to control the number of stacks to backtrace. The default is all.
Summary
The above is the detailed content of Detailed explanation of the use of debug_backtrace debugging function in php. For more information, please follow other related articles on the PHP Chinese website!