Zend_Debug::dump() is a really handy part of the framework that simply dumps the contents of whatever you give it to print_r and wraps it in <pre></pre>.
I got tired of typing it out every time, so I added the following shorthand functions to my bootstrap file. (The only acceptable use of a function in a bootstrap, in my mind.)
-
-
require_once("Zend/Debug.php"); // next time we’re going to talk about __autoload()
-
-
/**
-
* dd is a shorthand function for "dump and die". It takes whatever you give it and
-
* spits it to d(), then dies. Useful for debugging.
-
*/
-
-
function dd($val){
-
d($val);
-
}
-
-
/**
-
* This is so I don’t have to keep typing Zend_Debug::dump($whatever);
-
*/
-
function d($val){
-
Zend_Debug::dump($val);
-
}
October 13th, 2007 at 4:42 pm
Nice man. I’ve taken this a little further by allowing a ‘developer’ flag to ensure any calls that make it to production are at least hidden. Next level would be to post a warning instead so any that remain will be logged.
if ($config->developer == true){
$front->throwExceptions(true);
function d($val) { Zend_Debug::dump($val); }
function dd($val){ d($val); die(); }
} else {
function d($val) { return; }
function dd($val){ return; }
}
Thanks, Matt
January 3rd, 2008 at 12:06 pm
Nice. I must type Zend_Debug… at least 10 times a day. This is one of those things that you see and think, “Why didn’t I think of that?”
I make heavy use of the $label param myself, so I modded the functions to include both $label and $echo params, ie:
d($val, $label=”", $echo=true);
Works like a charm.