-
Notifications
You must be signed in to change notification settings - Fork 0
/
Debug.php
49 lines (40 loc) · 1.15 KB
/
Debug.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/**
* Used to help find how you get to a particular point in code.
*
* @param bool $completeTrace
*
* @return string
*/
function getCallingFunctionName($completeTrace = false)
{
$trace = debug_backtrace();
if ($completeTrace) {
$str = '';
foreach ($trace as $caller) {
// Skip trace output on the current tracing function
if ($caller['function'] == __FUNCTION__) {
continue;
}
#echo "Caller:<pre>" . print_r($caller, true) . "</pre>\n"; die();
$str .= " -- Called by {$caller['function']}";
if (isset($caller['line'])) {
$str .= " on line {$caller['line']}";
}
if (isset($caller['class'])) {
$str .= " From Class {$caller['class']}\n";
}
}
}
else {
$caller = $trace[3];
$str = "Called by {$caller['function']}";
if (isset($caller['line'])) {
$str .= " on line {$caller['line']}";
}
if (isset($caller['class'])) {
$str .= " From Class {$caller['class']}";
}
}
return "$str\n";
}