Wallogit.com
2017 © Pedro Peláez
A simple set of functions for PHP debugging
For easy debugging without x-debug. Works both in the browser aswel as in the terminal., (*1)
Install the composer package (https://packagist.org/packages/sanderheijselaar/ezdebug) or download and include the ezDebug.php file in your project, (*2)
$data1 = array(
'id' => 1,
'name' => 'Sander Heijselaar',
'country' => 'NL'
);
pr($data1, 'Array dump with pr');
Which will output the following:, (*3)
, (*4)
As you can see the data is dumped on screen and when you hover on a dump, it will tell you where the location of this dump is. This way you'll never have to search though your code to find all debug lines., (*5)
The same can be achieved by using the class, (*6)
use SanderHeijselaar\EzDebug\EzDebug;
$data1 = array(
'id' => 1,
'name' => 'Sander Heijselaar',
'country' => 'NL'
);
EzDebug::pr($data1, 'Array dump with pr');
All methods, except for prdiff & prdiffx will also work on the CLI., (*7)
, (*8)
Below is a list of the available methods that are at your disposal., (*9)
For almost every method there's method with the same name with an x behind it. This method will do exactly the same as the method without the x but will also exit at the end of the method., (*10)
The same applies for methods that end with an extra d at the end. Those methods do the same thing as the method without the d but will flush the output at the end of the method., (*11)
Almost every method has the same arguments, for example:, (*12)
pr($data, $label = '', $bgcolor = '', $color = '')
print the debug data on the screen using print_r, (*13)
pr($data, $label = '', $bgcolor = '', $color = '')
, (*14)
print the debug data on the screen using var_export, (*15)
prv($data, $label = '', $bgcolor = '', $color = '')
, (*16)
print the debug data on the screen using htmlentities, (*17)
prhe($data, $label = '', $bgcolor = '', $color = '')
, (*18)
print the backtrace on the screen using debug_backtrace(), (*19)
prbt($format = '', $label = '', $bgcolor = '', $color = '')
The format is eighter EzDebug::BtFormatFull EzDebug::BtFormatCompact. The compact option is default.
, (*20)
print the $_GET var on the screen, (*21)
prg($label = '', $bgcolor = '', $color = '')
There's no $data parameter because this method is dedicated to the use the $_GET as the $data. When no $label is provided, '__GET' will be displayed., (*22)
, (*23)
print the $_POST var on the screen, (*24)
prp($label = '', $bgcolor = '', $color = '')
There's no $data parameter because this method is dedicated to the use the $_POST as the $data. When no $label is provided, '__POST' will be displayed., (*25)
, (*26)
print the $_SESSION var on the screen, (*27)
prs($label = '', $bgcolor = '', $color = '')
There's no $data parameter because this method is dedicated to the use the $_SESSION as the $data. When no $label is provided, '__SESSION' will be displayed., (*28)
, (*29)
print the $_COOKIE var on the screen, (*30)
prc($label = '', $bgcolor = '', $color = '')
There's no $data parameter because this method is dedicated to the use the $_COOKIE as the $data. When no $label is provided, '__COOKIE' will be displayed., (*31)
, (*32)
print the $_FILES var on the screen, (*33)
prf($label = '', $bgcolor = '', $color = '')
There's no $data parameter because this method is dedicated to the use the $_FILES as the $data. When no $label is provided, '__FILES' will be displayed., (*34)
, (*35)
print the $_SERVER var on the screen, (*36)
prf($label = '', $bgcolor = '', $color = '')
There's no $data parameter because this method is dedicated to the use the $_SERVER as the $data. When no $label is provided, '__SERVER' will be displayed., (*37)
print formatted XML on the screen, (*38)
prxml(
"<note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note>",
$label = '',
$bgcolor = '',
$color = ''
);
, (*39)
*print the debug data on the screen using a < **textarea >, (*40)
prta($data, $label = '', $bgcolor = '', $color = '')
, (*41)
*print the current **line on the screen, (*42)
prta($data, $label = '', $bgcolor = '', $color = '')
, (*43)
*print the data to a **file instead of the screen. prfile will clear the file before writing the data to it. prfilea will append the dato the bottom of the file., (*44)
prfile($filename, $data)
, (*45)
prdiff($data1, $data2)
, (*46)
To distinguish the dumps when you have a screen filled with them, it's possible to pass any background and/or foreground color. My most used colors are:, (*47)
, (*48)
EzDebug::prd('EzDebug::C' . EzDebug::CLightGreen, 'OK', EzDebug::CLightGreen);
EzDebug::prd('EzDebug::C' . EzDebug::COrange, 'NOTIFICATION', EzDebug::COrange);
EzDebug::prd('EzDebug::C' . EzDebug::CLightCoral, 'ERROR', EzDebug::CLightCoral);
You can use the pre defined colors, but any other color code (#fff or green) will work., (*49)
There are alot of predefined colors in the class EzDebug::prcolors();
, (*50)
Licensed under MIT, (*51)