Personally, I never liked this fancy stuff, I use print_r() because it is not overwhelming and it gives enough information.
Here is my:
if(isset($_SERVER['HTTP_USER_AGENT']) && $_SERVER['HTTP_USER_AGENT'] == 'Debug') { echo '<strong><i>FILE : </i></strong>'.__FILE__.'<strong> <i>LINE : </i></strong>'.__LINE__.'<pre>'; print_r($var); echo '</pre>'; die; }
This if statement should ensure that other people do not see what you typed. Mozilla-Firefox and Google Chrome have a nice add-on called the "user agent switch" where you can create your own user agents. So I create a user agent called "Debug", and when I work, I change the user agent.
If I use the default user agent, nothing will happen, and the wont die; page die; , only you and the people who also change the user agent to "Debug" saw a printed variable. This is useful if you want to debug a problem in a production environment and do not want the page to die; , and itβs good if other people are also working on the project, and you donβt want to interrupt them by killing the page.
Then I exit the current file and line, this is useful when you are working in a framework or CMS or any other large project with thousands of files and folders and during debugging, if you can forget where you typed die; or exit; , and you need to remember where you were and what variables you printed.
I use the NetBeans IDE to develop PHP, I have a macro, so when you select a variable and use it, it inserts this debugging tool into a text editor and places the selection inside the print_r(); function print_r(); . If you also use NetBeans, you can use this macro:
cut-to-clipboard "if(isset($_SERVER['HTTP_USER_AGENT']) && $_SERVER['HTTP_USER_AGENT'] == 'Debug')" insert-break "{" insert-break "echo '<strong><i>FILE : </i></strong>'.__FILE__.'<strong> <i>LINE :</i></strong>'.__LINE__.'<pre>';" insert-break "print_r(" paste-from-clipboard remove-line-begin ");" insert-break "echo '</pre>';" insert-break "die;"
You just need to select $variable and use the macro.
shotex
source share