ebb/debug

Quick debugging toolkit for PHP


License
CC0-1.0

Documentation

Ebb - Debug

A set of tiny PHP debugging functions, to make life a tiny bit easier.

Output a flag to test complex logic

Calling i() simply outputs the file and line i() was called from, e.g. my/dir/file.php - 22, so you can quickly see if that point was reached in your application code.

Mainly useful if you've got a lot of complex logic and if conditions in a file, and you want to see if that point is ever reached.

// Finding the problem.
if (/* something */)
{
  i(); // Output a flag if we reached this point.
}
else
{
  i(); // Output a flag if we reached this point.
}

Debug a variable

Debug any variable in a neat way. A better replacement for var_dump()

// Debug the $var variable.
d($var); 

// Debug several variables at once.
d($a, $b, $c); 

Backtrace

Backtrace your route to a file. Removes as much crap as possible to make the trace easy to read.

// Output a neat backtrace.
b(); 

Benchmark/compare two or more functions

Compare the performance of two Closures. Used for comparing two equivalent blocks of code, to see which is faster.

Runs each closure 10,000 times, drops the top and bottom 10% (to defeat internal garbage collection). Lists the average execution time for each closure, and highlights which was fastest.

// Compare two (or more) closures.
c(
    function() { return strpos('a', 'abc') === 0; }, // e.g. 0.002 ms (winner)
    function() { return substr('abc', 0, 1) === 'a'; } // e.g. 0.003 ms
);

Time between two points

Find slowdowns in your application by measuring the time in ms between two points in a file. Calls to t() are paired, so each pair starts and then stops a timer.

// Something in this file is slow.
// Where is the slow code?

t(); // Start the timer.
// Some potentially slow code here.
t(); // End the timer: 0.002 ms — not that slow.

t(); // Start the timer.
// Some potentially slow code here.
t(); // End the timer: 28.5 ms — something in this block is slow!