Avinash
Avinash

Reputation: 6174

determine from where the function being called in php

I have one function on my code. say its xyz().

This function is being called from different files of my project.

Is there any way than I can get from where the function is being called.

I want below infromation:

File name from where its called. Line
number of that file. if call is from
inside the function then that function
name. Class name Class method name.

I know about use of magic constants like FILE and all that. but i don't want to pass all that in function call. like below:

xyz('msg',__FILE__,__CLASS__);

is there any way that i have to pass just my error related data only. and it will find the above details from where the function is called.

Upvotes: 0

Views: 440

Answers (2)

user432219
user432219

Reputation:

You can call debug_backtrace() function:

function myFunctionToDebug()
{
    var_dump(debug_backtrace());
}

This function returns an array with all information you need for debugging.

Upvotes: 2

Anirudh
Anirudh

Reputation: 388

Are you looking for debug_print_backtrace() or debug_backtrace() by any chance?

Upvotes: 0

Related Questions