Example #1
0
function get_trace_back()
{
    // based on PHP manual page for debug_backtrace()
    $trace_string = '';
    if (!version_compare(PHPVERSION(), '4.3', '>=')) {
        return $trace_string;
    }
    $trace = debug_backtrace();
    foreach ($trace as $line) {
        if (in_array($line['function'], array('raiseerror', 'trigger_error', 'errorhandlerdispatch', 'handleerror', 'handleframeworkerror', 'displaytraceback'))) {
            continue;
        }
        $trace_string .= '* ';
        if (isset($line['class'])) {
            $trace_string .= $line['class'];
            $trace_string .= ".";
        }
        $trace_string .= $line['function'];
        $trace_string .= "(";
        if (isset($line['args'])) {
            $sep = '';
            foreach ($line['args'] as $arg) {
                $trace_string .= $sep;
                $sep = ', ';
                if (is_null($arg)) {
                    $trace_string .= 'NULL';
                } elseif (is_array($arg)) {
                    $trace_string .= 'ARRAY[' . sizeof($arg) . ']';
                } elseif (is_object($arg)) {
                    $trace_string .= 'OBJECT:' . get_class($arg);
                } elseif (is_bool($arg)) {
                    $trace_string .= $arg ? 'TRUE' : 'FALSE';
                } else {
                    $trace_string .= '"';
                    $trace_string .= htmlspecialchars(substr((string) @$arg, 0, 32));
                    if (strlen($arg) > 32) {
                        $trace_string .= '...';
                    }
                    $trace_string .= '"';
                }
            }
        }
        $trace_string .= ")";
        if (isset($line['file'])) {
            $trace_string .= $line['file'];
            $trace_string .= " line ";
            $trace_string .= $line['line'];
        }
        $trace_string .= "\n\n";
    }
    return $trace_string;
}
Example #2
0
function fs_get_backtrace()
{
    $s = '';
    if (PHPVERSION() >= 4.3) {
        $MAXSTRLEN = 64;
        $s = '<pre align=left>';
        $traceArr = debug_backtrace();
        array_shift($traceArr);
        array_shift($traceArr);
        $tabs = sizeof($traceArr) - 1;
        foreach ($traceArr as $arr) {
            //for ($i=0; $i < $tabs; $i++) $s .= '&nbsp;';
            $s .= "&nbsp;&nbsp;";
            $tabs -= 1;
            $s .= '<font face="Courier New,Courier">';
            if (isset($arr['class'])) {
                $s .= $arr['class'] . '.';
            }
            /*
            foreach($arr['args'] as $v) {
            	if (is_null($v)) $args[] = 'null';
            	else if (is_array($v)) $args[] = 'Array['.sizeof($v).']';
            	else if (is_object($v)) $args[] = 'Object:'.get_class($v);
            	else if (is_bool($v)) $args[] = $v ? 'true' : 'false';
            	else {
            		$v = (string) @$v;
            		$str = htmlspecialchars(substr($v,0,$MAXSTRLEN));
            		if (strlen($v) > $MAXSTRLEN) $str .= '...';
            		$args[] = $str;
            	}
            }
            */
            $line = isset($arr['line']) ? $arr['line'] : '?';
            $file = isset($arr['file']) ? $arr['file'] : '';
            $args = array();
            $s .= $arr['function'] . '(' . implode(', ', $args) . ')';
            if (!empty($file)) {
                $s .= sprintf("</font><font color=#808080 size=-1> # line %4d," . " file: <a href=\"file:/%s\">%s</a></font>", $line, $file, $file);
            } else {
                $s .= sprintf("</font><font color=#808080 size=-1> # line %4d," . " unknown file</font>", $line);
            }
            $s .= "\n";
        }
        $s .= '</pre>';
    }
    return $s;
}
Example #3
0
function _adodb_backtrace($printOrArr = true, $levels = 9999)
{
    if (PHPVERSION() < 4.3) {
        return '';
    }
    $html = isset($_SERVER['HTTP_USER_AGENT']);
    $fmt = $html ? "</font><font color=#808080 size=-1> %% line %4d, file: <a href=\"file:/%s\">%s</a></font>" : "%% line %4d, file: %s";
    $MAXSTRLEN = 64;
    $s = $html ? '<pre align=left>' : '';
    if (is_array($printOrArr)) {
        $traceArr = $printOrArr;
    } else {
        $traceArr = debug_backtrace();
    }
    array_shift($traceArr);
    array_shift($traceArr);
    $tabs = sizeof($traceArr) - 2;
    foreach ($traceArr as $arr) {
        $levels -= 1;
        if ($levels < 0) {
            break;
        }
        $args = array();
        for ($i = 0; $i < $tabs; $i++) {
            $s .= $html ? ' &nbsp; ' : "\t";
        }
        $tabs -= 1;
        if ($html) {
            $s .= '<font face="Courier New,Courier">';
        }
        if (isset($arr['class'])) {
            $s .= $arr['class'] . '.';
        }
        if (isset($arr['args'])) {
            foreach ($arr['args'] as $v) {
                if (is_null($v)) {
                    $args[] = 'null';
                } else {
                    if (is_array($v)) {
                        $args[] = 'Array[' . sizeof($v) . ']';
                    } else {
                        if (is_object($v)) {
                            $args[] = 'Object:' . get_class($v);
                        } else {
                            if (is_bool($v)) {
                                $args[] = $v ? 'true' : 'false';
                            } else {
                                $v = (string) @$v;
                                $str = htmlspecialchars(substr($v, 0, $MAXSTRLEN));
                                if (strlen($v) > $MAXSTRLEN) {
                                    $str .= '...';
                                }
                                $args[] = $str;
                            }
                        }
                    }
                }
            }
        }
        $s .= $arr['function'] . '(' . implode(', ', $args) . ')';
        $s .= @sprintf($fmt, $arr['line'], $arr['file'], basename($arr['file']));
        $s .= "\n";
    }
    if ($html) {
        $s .= '</pre>';
    }
    if ($printOrArr) {
        print $s;
    }
    return $s;
}
Example #4
0
 function adodb_backtrace($print = true)
 {
     $s = '';
     if (PHPVERSION() >= 4.3) {
         $MAXSTRLEN = 64;
         $s = '<pre align=left>';
         $traceArr = debug_backtrace();
         array_shift($traceArr);
         $tabs = sizeof($traceArr) - 1;
         foreach ($traceArr as $arr) {
             for ($i = 0; $i < $tabs; $i++) {
                 $s .= ' &nbsp; ';
             }
             $tabs -= 1;
             $s .= '<font face="Courier New,Courier">';
             if (isset($arr['class'])) {
                 $s .= $arr['class'] . '.';
             }
             foreach ($arr['args'] as $v) {
                 if (is_null($v)) {
                     $args[] = 'null';
                 } else {
                     if (is_array($v)) {
                         $args[] = 'Array[' . sizeof($v) . ']';
                     } else {
                         if (is_object($v)) {
                             $args[] = 'Object:' . get_class($v);
                         } else {
                             if (is_bool($v)) {
                                 $args[] = $v ? 'true' : 'false';
                             } else {
                                 $v = (string) @$v;
                                 $str = htmlspecialchars(substr($v, 0, $MAXSTRLEN));
                                 if (strlen($v) > $MAXSTRLEN) {
                                     $str .= '...';
                                 }
                                 $args[] = $str;
                             }
                         }
                     }
                 }
             }
             $s .= $arr['function'] . '(' . implode(', ', $args) . ')';
             $s .= sprintf("</font><font color=#808080 size=-1> # line %4d, file: <a href=\"file:/%s\">%s</a></font>", $arr['line'], $arr['file'], $arr['file']);
             $s .= "\n";
         }
         $s .= '</pre>';
         if ($print) {
             print $s;
         }
     }
     return $s;
 }
Example #5
0
 function bt($levels = 9999, $iPrint = TRUE)
 {
     $s = '';
     if (PHPVERSION() >= 4.3) {
         $MAXSTRLEN = 64;
         $traceArr = debug_backtrace();
         array_shift($traceArr);
         $tabs = sizeof($traceArr) - 1;
         $indent = '';
         $sClass = '';
         foreach ($traceArr as $arr) {
             $levels -= 1;
             if ($levels < 0) {
                 break;
             }
             $args = array();
             for ($i = 0; $i <= $tabs; $i++) {
                 $indent .= '}';
             }
             $tabs -= 1;
             if (isset($arr['class'])) {
                 $sClass .= $arr['class'] . '::';
             }
             if (isset($arr['args'])) {
                 foreach ($arr['args'] as $v) {
                     if (is_null($v)) {
                         $args[] = 'null';
                     } elseif (is_array($v)) {
                         $args[] = 'Array[' . sizeof($v) . ']';
                     } elseif (is_object($v)) {
                         $args[] = 'Object:' . get_class($v);
                     } elseif (is_bool($v)) {
                         $args[] = $v ? 'true' : 'false';
                     } else {
                         $v = (string) @$v;
                         $str = htmlspecialchars(substr($v, 0, $MAXSTRLEN));
                         if (strlen($v) > $MAXSTRLEN) {
                             $str .= '...';
                         }
                         $args[] = $str;
                     }
                 }
             }
             if (!preg_match("*include*", $arr['function']) && !preg_match("*silentlog*", strtolower($arr['function']))) {
                 $s .= "\n    " . $indent . '    -> ';
                 $s .= $sClass . $arr['function'] . '(' . implode(', ', $args) . ')';
             }
             $s .= "\n    " . $indent;
             $s .= @sprintf(" LINE: %4d, %s", $arr['line'], $arr['file']);
             $indent = '';
         }
         $s .= "\n";
         if ($iPrint) {
             print '<pre>' . $s . "</pre>\n";
         }
     }
     return $s;
 }
Example #6
0
function adodb_backtrace($print = true, $backtrace = array())
{
    $s = "Stack Trace:\n";
    if (PHPVERSION() >= 4.3) {
        $MAXSTRLEN = 64;
        $s = '<pre align=left>';
        if (count($backtrace) == 0) {
            // Fetch the backtrace
            $traceArr = debug_backtrace();
        } else {
            $traceArr = $backtrace;
        }
        $tabs = sizeof($traceArr) - 1;
        foreach ($traceArr as $arr) {
            for ($i = 0; $i < $tabs; $i++) {
                $s .= '  ';
            }
            $tabs -= 1;
            if (isset($arr['class'])) {
                $s .= $arr['class'] . '.';
            }
            $args = array();
            if (isset($arr['args'])) {
                foreach ($arr['args'] as $v) {
                    if (is_null($v)) {
                        $args[] = 'null';
                    } else {
                        if (is_array($v)) {
                            $args[] = 'Array[' . sizeof($v) . ']';
                        } else {
                            if (is_object($v)) {
                                $args[] = 'Object:' . get_class($v);
                            } else {
                                if (is_bool($v)) {
                                    $args[] = $v ? 'true' : 'false';
                                } else {
                                    $v = (string) @$v;
                                    $str = htmlspecialchars(substr($v, 0, $MAXSTRLEN));
                                    if (strlen($v) > $MAXSTRLEN) {
                                        $str .= '...';
                                    }
                                    $args[] = $str;
                                }
                            }
                        }
                    }
                }
            }
            $reg = array();
            if (ereg('/([0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]+)/(.+)$', $arr['file'], $reg)) {
                $href = SVN_REPOSITORY . '/releases/' . $reg[1] . '/' . $reg[2];
            } else {
                $href = 'file://' . $arr['file'];
            }
            $s .= $arr['function'] . '(' . implode(', ', $args) . ')';
            $s .= sprintf("</font><font color=#808080 size=-1> # line %4d," . " file: <a href=\"%s\">%s</a></font>", $arr['line'], $href, $arr['file']);
            $s .= "\n";
        }
        $s .= '</pre>';
        if ($print) {
            print $s;
        }
    }
    return $s;
}