Debug function Debug_backtrace in PHP

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.