Return to Snippet

Revision: 60837
at November 13, 2012 05:18 by philsown


Initial Code
function dd($var)
{
    echo '<pre>' . fl() . dump($var) . PHP_EOL . PHP_EOL . 'dd() exit</pre>';
    exit();
}

function d($var)
{
    echo '<pre>' . fl() . dump($var) . '</pre>';
}

function fl()
{
    $dbbt = dbbt();
    return 'File: ' . basename($dbbt[0]['file']) . ' Line: ' . $dbbt[0]['line'] . ' - ';
}

function dbbt()
{
    $dbbt = debug_backtrace();
    array_shift($dbbt);
    array_shift($dbbt);
    return $dbbt;
}

function dump($var)
{
    if (is_string($var) && '' == $var) {
        $var = 'string(' . strlen($var) . ') ""';
    } elseif (is_array($var) && empty($var)) {
        $var = 'array(0) empty';
    } elseif (is_bool($var)) {
        $var = 'boolean ' . ((true === $var) ? 'true' : 'false');
    } elseif (null === $var) {
        $var = 'null';
    }

    return print_r($var, true);
}

Initial URL

                                

Initial Description
A little pile of functions I use for implementing a nice var dump alternative.

Initial Title
Var Debug or Dump Library

Initial Tags
debug

Initial Language
PHP