• PHP 使用 debug_print_backtrace() 或 debug_backtrace() 打印栈轨迹


    <?php
    
    /* 使用debug_print_backtrace() 或 debug_backtrace() 打印栈轨迹 */
    
    function fun1() {
    	print "Hello world!
    ";
    	fun2();
    }
    
    function fun2() {
    	Class1::fun3();
    }
    
    Class Class1 {
    	static function fun3() {
    		$class2 = new Class2();
    		$class2->fun4();
    	}
    }
    
    class Class2 {
    	function fun4() {
    		debug_print_backtrace();
    		$backtrace = debug_backtrace();
    		echo '<pre>';
    		print_r($backtrace);
    	}
    }
    
    fun1();
    

    输出:

    Hello world!
    #0  Class2->fun4() called at [D:wampwwwpractisephpphpcookbookerror	rack.php.php:17]
    #1  Class1::fun3() called at [D:wampwwwpractisephpphpcookbookerror	rack.php.php:11]
    #2  fun2() called at [D:wampwwwpractisephpphpcookbookerror	rack.php.php:7]
    #3  fun1() called at [D:wampwwwpractisephpphpcookbookerror	rack.php.php:30]
    <pre>Array
    (
    	[0] => Array
        (
    	    [file] => D:wampwwwpractisephpphpcookbookerror	rack.php.php
    	    [line] => 17
    	    [function] => fun4
    	    [class] => Class2
    	    [object] => Class2 Object
            (
            )
    
    	    [type] => ->
    	    [args] => Array
            (
            )
        )
    
    	[1] => Array
    	    (
            [file] => D:wampwwwpractisephpphpcookbookerror	rack.php.php
            [line] => 11
            [function] => fun3
            [class] => Class1
            [type] => ::
            [args] => Array
              (
              )
        )
    
    	[2] => Array
        (
          [file] => D:wampwwwpractisephpphpcookbookerror	rack.php.php
          [line] => 7
          [function] => fun2
          [args] => Array
            (
            )
        )
    
    	[3] => Array
        (
          [file] => D:wampwwwpractisephpphpcookbookerror	rack.php.php
          [line] => 30
          [function] => fun1
          [args] => Array
            (
            )
        )
    )
    

      

    参考:

    <PHP Cookbook>3'rd  

  • 相关阅读:
    Solr 配置连接数据库
    最大利润
    分割金条的最小代价
    民居点亮
    一个会议室最多安排几场宣讲
    N皇后问题
    Integer的缓存机制
    Windows快捷键
    二叉树中两个节点的最低公共祖节点
    判断二叉树是不是完全二叉树
  • 原文地址:https://www.cnblogs.com/dee0912/p/5474138.html
Copyright © 2020-2023  润新知