PHP custom debugging functions

Here is another debugging helper for Symfony, CodeIgniter, Kohana and Zend frameworks or your applications. Normally you would use var_dump() or print _r() for debugging but dumping the data without xdebug always a pain.

I use these custom functions depending on type of data whether an array or a class to debug my code which makes it more friendly and human-readable.


<?php

function my_print_r ($param, $bool = TRUE) {
    pre( print_r($param, $bool), FALSE);
}

function my_var_dump ($param) {
    pre(var_dump($param));
}

function my_debug ($param) {
    if (is_object($param)) {
        pre('Object: ['.get_class($param). '] => '
           . print_r(array_keys(get_object_vars($param)), TRUE), FALSE);
    }
}

function my_debug_in ($param) {
    if (is_object($param)) {
        pre('Object: [' .get_class($param).' ] => Array', FALSE);
        foreach (get_object_vars($param) as $key) {
            my_debug($key);
        }
    }
    if (is_array($param)) {
        my_print_r($param);
    }
}

function my_class($name = NULL) {
    $class = new ReflectionClass($name);
    my_print_r(Reflection::export($class));
   
}

function pre($param, $bool = TRUE) {
    if (!ini_get('xdebug.default_enable') || !$bool) {
        echo "<pre>".$param ."</pre>\n";
    }else {
        echo $param;
    }
}

?>
Share this