Giter Site home page Giter Site logo

bugger's Introduction

Bugger

Build Status Coverage Status Latest Stable Version License

Bugger is a collection of functions for debugging PHP code. Use it to:

  • Dump information about a variable
  • Set breakpoints in loops

Bugger is designed to be used when remote debugger is not available. It allows to dump information about a variable together with the debug backtrace (trace method), it allows to collect information about multiple variables during the script execution and dump them at the end of the script execution (stack method), as well as trap iterations (tick method).

API

Bugger API is exposed to the global namespace via three functions:

Trace

/**
 * Terminates the script, discards the output buffer, dumps information about the expression including backtrace up to the `trace` call.
 * 
 * @param mixed $expression The variable you want to dump.
 * @return null
 */
trace ( mixed $expression );

Trace is used to dump information about the expression including the backtrace information. Trace will attempt to discard existing output buffer. If output buffer cannot be discaded because it has been already sent to the browser, then Bugger will attempt to clear the previous output using client-side script.

Trace output

Stack

/**
 * Stacks information about the expression and dumps the stack at the end of the script execution.
 *
 * @param mixed $expression The variable you want to dump.
 * @return null
 */
stack ( mixed $expression );

Stack is identical to trace except that calling stack will not terminate the script at the time of the call. If stack is called at least once during the script execution, then at the end of the script execution output buffer will be discarded and replaced with the collected stack dump, e.g.

echo 'foo';
stack('a');
echo 'bar';
stack('b');
echo 'baz';
stack('c');
echo 'qux';

In the above example, 'foo', 'bar', 'baz' and 'qux' will be discarded.

Stack output

Tick

/**
 * Tracks the number of times tick function itself has been called and returns true
 * when the desired number within the namespace is reached.
 *
 * @param int $true_after Number of the itteration after which response is true.
 * @param string $namespace Itteration namespace.
 * @return boolean
 */
tick ( int $true_after [, string $namespace = 'default' ] )

tick is used to catch script execution in loop or recursive calls. tick returns true when it has been executed a predefined number of times or more, e.g.

while (true) {
    if (tick(10)) {
        // Tick will return true after 10 itterations.
        break;
    }
}

tick(4, 'test'); // false
tick(4, 'test'); // false
tick(4, 'test'); // false
tick(4, 'test'); // true
tick(4, 'test'); // true
tick(4, 'test'); // true

tick can be used together with stack or trace to capture the state of a particular itteration or multiple itterations.

Tick output

Installation

The recommended way to use Bugger is through Composer.

{
    "require": {
       "gajus/bugger": "0.2.*"
    }
}

If you want to use Bugger across the server, then use auto_prepend_file setting to load ./src/autoload.php.

Roadmap

  • Support CLI.

bugger's People

Contributors

gajus avatar potherca avatar sumpygump avatar

Watchers

domainbank avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.