Base::trace PHP Method

trace() public method

Return filtered stack trace as a formatted string (or array)
public trace ( array $trace = NULL, $format = TRUE ) : string | array
$trace array array|NULL
$format bool
return string | array
    function trace(array $trace = NULL, $format = TRUE)
    {
        if (!$trace) {
            $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
            $frame = $trace[0];
            if (isset($frame['file']) && $frame['file'] == __FILE__) {
                array_shift($trace);
            }
        }
        $debug = $this->hive['DEBUG'];
        $trace = array_filter($trace, function ($frame) use($debug) {
            return $debug && isset($frame['file']) && ($frame['file'] != __FILE__ || $debug > 1) && (empty($frame['function']) || !preg_match('/^(?:(?:trigger|user)_error|' . '__call|call_user_func)/', $frame['function']));
        });
        if (!$format) {
            return $trace;
        }
        $out = '';
        $eol = "\n";
        // Analyze stack trace
        foreach ($trace as $frame) {
            $line = '';
            if (isset($frame['class'])) {
                $line .= $frame['class'] . $frame['type'];
            }
            if (isset($frame['function'])) {
                $line .= $frame['function'] . '(' . ($debug > 2 && isset($frame['args']) ? $this->csv($frame['args']) : '') . ')';
            }
            $src = $this->fixslashes(str_replace($_SERVER['DOCUMENT_ROOT'] . '/', '', $frame['file'])) . ':' . $frame['line'];
            $out .= '[' . $src . '] ' . $line . $eol;
        }
        return $out;
    }