Skip to content

Instantly share code, notes, and snippets.

@meonkeys
Created July 9, 2013 17:50
Show Gist options
  • Save meonkeys/5959547 to your computer and use it in GitHub Desktop.
Save meonkeys/5959547 to your computer and use it in GitHub Desktop.
Run this within NetBeans PHP and you get a clickable stack trace. Files and line numbers link directly to the relevant code locations. Use in conjunction with https://gist.github.com/meonkeys/5959455 .
<?php
$pathMap = [
'/vagrant' => '/home/user/git/code',
];
$trace = '
/vagrant/foo/bar/Pager.php (131)
/vagrant/foo/bar/Main.php (25)
';
foreach (preg_split('/\n/', $trace) as $traceLine) {
$traceLine = trim($traceLine);
if (preg_match('/([^\s]*)\s+\((\d+)\)/', $traceLine, $matches) < 1) {
continue;
}
$file = $matches[1];
$linenum = $matches[2];
foreach ($pathMap as $old => $new) {
$file = preg_replace("#$old#", $new, $file);
}
print " in $file on line $linenum\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment