2017 © Pedro Peláez
 

library ezdebug

A simple set of functions for PHP debugging

image

sanderheijselaar/ezdebug

A simple set of functions for PHP debugging

  • Tuesday, July 10, 2018
  • by sheijselaar
  • Repository
  • 1 Watchers
  • 0 Stars
  • 34 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

EZ DEBUG

For easy debugging without x-debug. Works both in the browser aswel as in the terminal., (*1)

Installation

Install the composer package (https://packagist.org/packages/sanderheijselaar/ezdebug) or download and include the ezDebug.php file in your project, (*2)

Quick usage

$data1 = array(
    'id' => 1,
    'name' => 'Sander Heijselaar',
    'country' => 'NL'
);

pr($data1, 'Array dump with pr');

Which will output the following:, (*3)

Alt text, (*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)

Usage with the Class

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)

Alt text, (*8)

Methods

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)

Arguments

Almost every method has the same arguments, for example:, (*12)

pr($data, $label = '', $bgcolor = '', $color = '')
  • $data is the data that needs to be dumped
  • $label is the optional label that's shown on top of the data
  • $bgcolor is the optional background color. See all the available colors below
  • $color is the optional text color. See all the available colors below

pr, prd & prx

print the debug data on the screen using print_r, (*13)

pr($data, $label = '', $bgcolor = '', $color = '')

Alt text, (*14)

prv, prvd & prvx

print the debug data on the screen using var_export, (*15)

prv($data, $label = '', $bgcolor = '', $color = '')

Alt text, (*16)

prhe & prhex

print the debug data on the screen using htmlentities, (*17)

prhe($data, $label = '', $bgcolor = '', $color = '')

Alt text, (*18)

prbt & prbtx

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. Alt text, (*20)

prg & prgx

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)

Alt text, (*23)

prp & prpx

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)

Alt text, (*26)

prs & prsx

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)

Alt text, (*29)

prc & prcx

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)

Alt text, (*32)

prf & prfx

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)

Alt text, (*35)

prsvr & prsvrx

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)

prxml, prxmld & prxmlx

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 = ''
);

Alt text, (*39)

prta & prtax

*print the debug data on the screen using a < **textarea >, (*40)

prta($data, $label = '', $bgcolor = '', $color = '')

Alt text, (*41)

prl, prld & prlx

*print the current **line on the screen, (*42)

prta($data, $label = '', $bgcolor = '', $color = '')

Alt text, (*43)

prfile & prfilea

*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)

Alt text, (*45)

prdiff & prdiffx

prdiff($data1, $data2)

Alt text, (*46)

Colors

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)

Alt text, (*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)

All available colors

There are alot of predefined colors in the class

EzDebug::prcolors();    

Alt text, (*50)

Acknowledgements

  • I'm using Stephen Morley's Diff Class, which you can find more about at http://code.stephenmorley.org/php/diff-implementation/

Licensed under MIT, (*51)

The Versions

10/07 2018

dev-master

9999999-dev

A simple set of functions for PHP debugging

  Sources   Download

MIT

by Sander Heijselaar

debug php

10/07 2018

0.1.3

0.1.3.0

A simple set of functions for PHP debugging

  Sources   Download

MIT

by Sander Heijselaar

debug php

25/01 2017

0.1.2

0.1.2.0

A simple set of functions for PHP debugging

  Sources   Download

MIT

by Sander Heijselaar

debug php

14/01 2016

0.1.1

0.1.1.0

A simple set of functions for PHP debugging

  Sources   Download

MIT

by Sander Heijselaar

debug php

16/12 2015

0.1.0

0.1.0.0

A simple set of functions for PHP debugging

  Sources   Download

MIT

by Sander Heijselaar

debug php