Couple of convenience methods to add to your bootstrap.php

Although most of the convenience methods will be removed from CakePHP going forward (see the note about basics.php), and I say good riddance, you still have the opportunity to add your own to bootstrap.php.

For example a couple that I like are wrappers for var_dump(). The main reason being is that var_dump() will properly display NULL and FALSE. Unlike debug() and pr() (alias to) print_r(), which will show… well… nothing.

So here you go:

function vd($var) {
  if(Configure::read() > 0) {
    echo '<pre>';
      echo var_dump($var);
    echo '</pre>';
  }
}

Or, if you’d like to die() out:

function vdd($var) {
  if(Configure::read() > 0) {
      die(var_dump($var));
  }
}
%d bloggers like this: