PHP debug_backtrace () called by register_tick_function () does not return a full stack

I want to use register_tick_function()to connect the following calls and print a stack trace with debug_backtrace().

If I run the following code.

<?php

function dump() {
  // Replace this with var_dump(debug_backtrace()); to print the entire trace.
  foreach (debug_backtrace() as $trace)
    echo("Function ${trace['function']}() has been called" . PHP_EOL);
}

declare(ticks = 1);
register_tick_function('dump');

print("");
array_search('green', Array());

It prints only a function dump().

Function dump() has been called
Function dump() has been called
Function dump() has been called

Why can't I see the trace data print()and array_search()? He, like the stack, was reset before the call dump(). I am also sure that it worked correctly in the past.

+6
source share
1 answer

, , , PHP , , PHP .

, , , , . , .

class Foo {
    public static function bar() {
        return self::say();
    }

    public static function say() {
        return debug_backtrace();
    }
}

var_dump(Foo::say());
//[0] => say()

var_dump(Foo::bar());
//[0] => say();
//[1] => bar();

//Note that this behaviour work the same for require(), include() and eval()

require_once('test.php');

//test.php:
var_dump(debug_backtrace());
//[0] => require_once()

PHP script, , . backtrace , PHP , .

, : PHP

+1

All Articles