Skip to content

Instantly share code, notes, and snippets.

@Danack
Created October 8, 2015 16:37
Show Gist options
  • Save Danack/7448636d13bd3468bb9f to your computer and use it in GitHub Desktop.
Save Danack/7448636d13bd3468bb9f to your computer and use it in GitHub Desktop.
cuf stack trace
<?php
/*
as cuf
#0 /documents/projects/github/Blog/Blog/src/test.php(25): bbq()
#1 [internal function]: omg()
#2 /documents/projects/github/Blog/Blog/src/test.php(6): call_user_func('omg')
#3 {main}
as func call
#0 /documents/projects/github/Blog/Blog/src/test.php(25): bbq()
#1 /documents/projects/github/Blog/Blog/src/test.php(15): omg()
#2 {main}
*/
try {
echo "as cuf\n";
call_user_func('omg');
}
catch (\Exception $e) {
echo $e->getTraceAsString();
}
echo "\n\n";
try {
omg();
}
catch (\Exception $e) {
echo "as func call\n";
echo $e->getTraceAsString();
}
function omg()
{
bbq();
}
function bbq()
{
throw new \Exception("testing");
}
function getExceptionString(\Exception $ex) {
$string = '';
while ($ex) {
$string .= "Exception " . get_class($ex) . ': ' . $ex->getMessage()."\n";
foreach ($ex->getTrace() as $tracePart) {
$line = false;
$string .= var_export($tracePart, true);
$string .= "\n";
if (isset($tracePart['file']) ) {
$line .= $tracePart['file']." ";
}
if (isset($tracePart['line']) ) {
$line .= $tracePart['line']." ";
}
if (isset($tracePart["class"])) {
$line .= $tracePart["class"];
}
if (isset($tracePart["type"])) {
$line .= $tracePart["type"];
}
if (isset($tracePart["function"])) {
$line .= $tracePart["function"];
}
if ($line === false) {
$string .= "***\n";
}
else {
$string .= $line."\n";
}
}
$ex = $ex->getPrevious();
if ($ex) {
$string .= "Previous ";
}
};
return $string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment