![]() |
|
Snippets |
|
This function allows you to dump the value of a variable or an object.If available the function tells the file, line, function, class where it was called.
The object/variable to debug
The name that you want to give to the debuged object (var by default)
Allows you can stop the process or not. If the process is not stopped the debug message is available in the sf debug bar.
/** * Function that dumps an array or an object in the SF debug infos or * on s"\n"een/console * * @param $var mixed variable to dump * @param $die boolean Tells the function to stop the process or not * * @author Vernet Loic * @since 24 sept. 2006 */ public static function dump($var, $name = 'var', $die = false) { ob_start(); print('<br/><pre>'. $name . ' :<br/>'); print_r($var); print('</pre></br>'); $buffer = ob_get_contents(); ob_end_clean(); $backtrace = debug_backtrace(); $dieMsg = '<pre><b>var dump by goTools:dump()</b>'. "\n"; $dieMsg .= isset($backtrace[0]['file']) ? '» file : <b>'. $backtrace[0]['file'] .'</b>'. "\n" : ''; $dieMsg .= isset($backtrace[0]['line']) ? '» line : <b>'. $backtrace[0]['line'] .'</b>'. "\n" : ''; $dieMsg .= isset($backtrace[1]['class']) ? '» class : <b>'. $backtrace[1]['class'] .'</b>'. "\n" : ''; $dieMsg .= isset($backtrace[1]['function']) ? '» function : <b>'. $backtrace[1]['function'] .'</b>'. "\n" : ''; $dieMsg .= '</pre>'; print($buffer); if ($die == true) { die($dieMsg); } else { print($dieMsg); sfWebDebug::getInstance()->logShortMessage($buffer); } }
Comments on this snippet
Don't forget to define "CR" constant or replace it by "\n" or something else ;-)
That's write, it was a class constant. I have replaced it.
Note that installing xdebug (on your dev server) and call var_dump() has the same effect + nice colorization :)
Note that installing windows on your computer could destroy it. + nice fireworks ;)