topherg
topherg

Reputation: 4303

Getting the filename of where a function was called from

Is it possible (in an efficient manor) to retrieve the filename (and line if possible) of the previous command that called a function in another (included) file?

For example:

Foo.php

function foo() {
    bar();
}

Bar.php

function bar() {
    // some stuff that will show when the above is executed:
    // Foo.php, line 2 (last bit if possible)
}

Upvotes: 2

Views: 54

Answers (1)

hek2mgl
hek2mgl

Reputation: 158250

Thats a job for debug_backtrace():

function test($param)
{
    echo "$param";
    var_dump(debug_backtrace());
}

Upvotes: 5

Related Questions