Sample Code for debugging the debug_backtrace function in PHP,

Source: Internet
Author: User

Sample Code for debugging the debug_backtrace function in PHP,

Preface

If we want to know who called a method? Debug_backtrace can solve this problem. Debug_backtrace () can print out the call process of a page, from where to see clearly.

Sometimes we want to know the call stack of this function or method, that is, how it is called at the first level. We can print it using the debug_backtrace function of PHP, just 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-> token T (['_ token',' _ method']); return redirect ()-> route ('egretgame. index')-> with ('success', 'edited! ');}

You can control the number of stack levels to be traced back. The first parameter of debug_backtrace is a constant by default.DEBUG_BACKTRACE_PROVIDE_OBJECTThe information of this object is displayed. The second parameter is used to control the number of backtracing stacks. The default value is all.

Results:

PHP official documentation: http://php.net/manual/zh/function.debug-backtrace.php

Summary

The above is all the content of this article. I hope the content of this article has some reference and learning value for everyone's learning or work. If you have any questions, please leave a message to us, thank you for your support.

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.