Dump function for when there\'s no xDebug present.


/ Published in: PHP
Save to your folder(s)

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

Shorter than:
<pre> var_dump($something); exit;</pre>
if you use the $exit argument.

Also shorter than:
<pre>echo "&lt;pre&gt;"; var_dump($something); echo "&lt;/pre&gt;"; exit;</pre>
too.


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.