Posted By

philsown on 07/15/11


Tagged

debugging


Versions (?)

Dump function for when there's no xDebug present.


 / Published in: PHP
 

For when xDebug is not enabled and you want to echo/dump a variable.

Shorter than:

 var_dump($something); exit;
if you use the $exit argument.

Also shorter than:

echo "<pre>"; var_dump($something); echo "</pre>"; exit;
too.

  1. function dump($var, $exit = false) {
  2. if(is_string($var) && '' == $var) {
  3. $var = 'string(0) ""';
  4. } elseif(is_array($var) && empty($var)) {
  5. $var = 'array(0) empty';
  6. } elseif(is_bool($var)) {
  7. $var = 'boolean ' . ((true === $var) ? 'true' : 'false');
  8. } elseif(null === $var) {
  9. $var = 'null';
  10. }
  11.  
  12. echo '<pre>', print_r($var, true), '</pre>';
  13.  
  14. if(true == $exit) {
  15. exit('<pre>dump exit</pre>');
  16. }
  17. }

Report this snippet  

You need to login to post a comment.