Useful PHP debug functions

Here are a few useful PHP debug functions.

I wrote a similar post sometime ago posting the abbreviated “pr” function as a shorthand replacement for the “prinr_r” or “var_dump” functions. Since then this function has changed a bit so re-posting it here with the improvements. With the new updated function one can restrict the output to screen for specific IP address only.

Lets start by defining the IP address at the top for which you want to display the debug output. If you do not care about displaying output to browser for a specific IP (in case you are on development mode) just comment the following two lines out.

Next one is a shorthand for die() function. You can restrict a die based on the IP address or just die your script with line number.

You can output the javascript source code with the following function. By default it does not generate the “<script>” tag. If you want to generate the “<script>” tag just pas the second argument as true. For example, <code>djs(‘alert(“Hi”)’, true)</code>

Finally, below is the debug function named “pr”. This useful php debug function is a shorthand mix of the popular print_r and var_dump functions. It can be used to print output on a live website while using a check for ip address or the debug output can be emailed.

It works similar to one posted previously except a few changes which includes the inclusion of IP check and line number in the HTML source code

Leave a Reply