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

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

bugger's Issues

Data dump depth limit

Extension to #2

There are many situations when objects store related objects inside, that objects store another ones and so on. To not dump very long lists can be useful to make a customizable depth limit (as an argument to dump function) with a some default one about 3-5 levels.

Arguments in output should be clearer

It seems odd that it is var_dumping an array of values in the stack trace. This is because on line 45 of template.php it is var_dumping the arguments of the function call, but it should maybe split these out, and say "Argument 1: ..., Argument 2:..." instead of just show an array, to make it more clear what we're looking at.

Make the unit test runable without requiring composer

Currently the unit tests fail if you don't install bugger via composer

Warning: require(/var/www/html/scott/tmp/bugger/tests/../vendor/autoload.php): failed to open stream: No such file or directory in /var/www/html/scott/tmp/bugger/tests/bootstrap.php on line 2

Fatal error: require(): Failed opening required '/var/www/html/scott/tmp/bugger/tests/../vendor/autoload.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/scott/tmp/bugger/tests/bootstrap.php on line 2

As the vendor directory isn't present if you don't use composer to install.

Add data dump

It would be useful to add var_dump() and print_r() alternative to dump variables content, name (to not write it manually) and, maybe, location where dump called. Something like:

<?php

$var = 'Test string';
dump($var);
script.php:3
$var string(11) "Test string"

Implement way to disable debugger

Document and implement some way to turn off the dumping completely. Something like \Gajus\Bugger\Bugger::disable() would be good.

Rename BumpException to BuggerException

I have walked through the codebase & encountered the BumpException class, my first thought was:

What is a Bump?

Some research revealed that Bugger used to be called Bump. Renaming a project is valid enough, but not renaming this exception is slightly confusing. Also because the namespace still says Bump

Data dump formatting

Extension to #2

Printed data can be parsed/formatted based on its type to be more convenient. For example:

  • arrays as tables (one- or two-dimensional) or foldable trees
  • objects as foldable trees with class names and inner data names, types, contents
  • xml/html/json/yaml/etc as foldable trees or formatted source
  • timestamps as parsed datetime

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.