×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
2
Language: PHP
Posted by: Jeremy Brown
Added: Dec 28, 2015 2:49 PM
Modified: Dec 29, 2015 6:35 PM
Views: 43
Tags: debug php
Slightly silly, ugly block of code to output an array, data object, object properties, or one of the preloaded suggestions that are commented out below. It is very handy when your debugger is not an option for one reason or another, but you might find it handy anyway. My goals were:

1) output that is clearly distinct from the page content
2) protection against forgetting where I placed the damn debug snippet (it tells you)
3) there was a third thing, I swear

I most often use print_r because I want to understand the data array or object, but var_export is perfect for when you want the output to be valid code. I cannot recall why I would ever use var_dump.

Just for fun: by default the output is styled to look like a terminal window. I like that because I never mistake it for true page content. But you can toggle to the other style, with white background by changing from this:
echo '<div id="debugOutputBox_dark">
to this:
echo '<div id="debugOutputBox_light">

If you think this is stupid, then consider how stupid it is that you have read this far. So I'm laughing all the way to the stupid bank.:-P
  1. /***************DEBUG CODE - PLEASE REMOVE WHEN DONE TESTING***************/
  2. echo '<style>#debugOutputBox_dark{padding:5px;border:1px solid #999;width:95%;overflow:scroll;margin:5px;margin-left:10px;background-color:#000;color:#55ccff;font-family:tahoma;font-size:11pt;}</style>';
  3.  
  4. echo '<style>#debugOutputBox_light{padding:5px;border:1px solid #999;width:95%;overflow:scroll;margin:5px;margin-left:10px;background-color:#fff;color:#333;font-family:tahoma;font-size:11pt;}</style>';
  5.  
  6. echo '<div id="debugOutputBox_dark"><span style="color:red">' . __FILE__ . ', line <em>' . __LINE__ . '</em></span><pre>';
  7.  
  8. //$data = get_defined_vars();
  9. //$data = get_declared_classes();
  10. //$data = get_defined_constants();
  11. //$data = get_defined_functions();
  12. //$data = $_SESSION;
  13. //$data = $_SERVER;
  14. //$data = $_POST;
  15. //$data = $_GET;
  16. //$data = $_REQUEST;
  17. $data = get_object_vars($this);
  18.  
  19. print_r($data);
  20. //var_dump($data);
  21. //var_export($data);
  22.  
  23. echo '</pre></div>';
  24. /***************************************END DEBUG CODE******************************************/