debug_backtrace()
是你的朋友吗
这就是我们用来转储
现在的
线。要根据您的情况进行调整,请忽略
$trace
数组。
class Util_Debug_ContextReader {
private static function the_trace_entry_to_return() {
$trace = debug_backtrace();
for ($i = 0; $i < count($trace); ++$i) {
if ('debug' == $trace[$i]['function']) {
if (isset($trace[$i + 1]['class'])) {
return array(
'class' => $trace[$i + 1]['class'],
'line' => $trace[$i]['line'],
);
}
return array(
'file' => $trace[$i]['file'],
'line' => $trace[$i]['line'],
);
}
}
return $trace[0];
}
/**
* @return string
*/
public function current_module() {
$trace_entry = self::the_trace_entry_to_return();
if (isset($trace_entry['class']))
return 'class '. $trace_entry['class'];
else
return 'file '. $trace_entry['file'];
return 'unknown';
}
public function current_line_number() {
$trace_entry = self::the_trace_entry_to_return();
if (isset($trace_entry['line'])) return $trace_entry['line'];
return 'unknown';
}
}