Code snippets for symfony 1.x


Debug an object or variable with additional informations

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.

1st parameter

The object/variable to debug

2nd parameter

The name that you want to give to the debuged object (var by default)

3nd parameter

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)
      print('<br/><pre>'. $name . ' :<br/>');
      $buffer = ob_get_contents();
      $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>';
      if ($die == true) {
      } else {
by Loïc Vernet on 2007-12-20, tagged debug 

Comments on this snippet

gravatar icon
#1 JeremY B on 2007-12-26 at 11:37

Don't forget to define "CR" constant or replace it by "\n" or something else ;-)

gravatar icon
#2 Loïc Vernet on 2008-01-01 at 02:55

That's write, it was a class constant. I have replaced it.

gravatar icon
#3 Nicolas Chambrier on 2008-01-03 at 11:05

Note that installing xdebug (on your dev server) and call var_dump() has the same effect + nice colorization :)

gravatar icon
#4 Loïc Vernet on 2008-01-04 at 11:24

Note that installing windows on your computer could destroy it. + nice fireworks ;)