is there a way to find out, where a function in PHP was called from? example:
function epic() { fail(); } function fail() { //at this point, how do i know, that epic() has called this function? }
If you use an IDE like Netbeans, you can CTRL+Click the function use and it will take you to where it is defined, assuming the file is within the project folder you defined.
isset($return)){ $return = findFunction($function, $inputDirectory."/". $folder); } else if($return == false){ $return = findFunction($function, $inputDirectory."/". $folder); } } } else { return false; } } findFunction("testFunction", "rootDirectory");
The debug_backtrace() function generates a PHP backtrace. This function displays data from the code that led up to the debug_backtrace() function. Returns an array of associative arrays.
PHP Function Arguments Information can be passed to functions through arguments. An argument is just like a variable. Arguments are specified after the function name, inside the parentheses. You can add as many arguments as you want, just separate them with a comma.
You can use debug_backtrace()
.
Example:
<?php function epic( $a, $b ) { fail( $a . ' ' . $b ); } function fail( $string ) { $backtrace = debug_backtrace(); print_r( $backtrace ); } epic( 'Hello', 'World' );
Output:
Array ( [0] => Array ( [file] => /Users/romac/Desktop/test.php [line] => 5 [function] => fail [args] => Array ( [0] => Hello World ) ) [1] => Array ( [file] => /Users/romac/Desktop/test.php [line] => 15 [function] => epic [args] => Array ( [0] => Hello [1] => World ) ) )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With