Skip to content

Instantly share code, notes, and snippets.

@neves
Created November 8, 2013 17:07
Show Gist options
  • Save neves/7374235 to your computer and use it in GitHub Desktop.
Save neves/7374235 to your computer and use it in GitHub Desktop.
PHP clean backtrace
<?php
function backtrace()
{
$backtrace = debug_backtrace();
$log = "\n";
$root = @$_SERVER['DOCUMENT_ROOT'];
foreach ($backtrace as $trace) {
$class = "";
$type = "";
extract($trace);
if ($root && strpos($file, $root) === 0) {
$file = substr($file, strlen($root));
}
$log .= "$file:$line\t${class}${type}${function}()\n";
}
return $log;
}
<?php
class Teste
{
static function instance() {
$t = new Teste();
$t->foo();
}
function foo()
{
trigger_error(backtrace());
}
}
function teste($a = 2)
{
Teste::instance();
}
$f = function () {
teste(45);
};
$f();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment