Simple and Extensible PHP Dumper
#1 Compare This branch is 1 commit ahead, 305 commits behind raulfraile:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Ladybug: Simple and Extensible PHP Dumper

Build Status

Ladybug provides an easy and extensible var_dump/print_r replacement for PHP 5.3+ projects. For example, with this library, the following is possible:

    $var1 = NULL;
    $var2 = 15;
    $var3 = 15.5;
    $var4 = 'hello world!';
    $var5 = false;

    ladybug_dump($var1, $var2, $var3, $var4, $var5);

As a result:

int 15
float 15.5
string(12) "hello world!"
bool FALSE


It is possible to dump any variable, including arrays, objects and resources:

Dumping an array

    $var = array(
            'name' => 'Raul',
            'age' => 29
            'name' => 'John',
            'age' => 27


Dumping an object

    $var = new Foo();

Dumping a mysql resultset

    $connection = mysql_connect('localhost', 'dbuser', 'dbpassword');
    mysql_select_db('dbname', $connection);
    $result = mysql_query('SELECT * FROM user', $connection);


Dumping a GD image

    $img = imagecreatefrompng(__DIR__ . '/images/ladybug.png');

CLI (Command-line interface) support

$ php examples/array.php

There are more examples in examples directory.


Using Composer (recommended)

Composer is a project dependency manager for PHP. You have to list your dependencies in a composer.json file:

    "require": {
        "raulfraile/ladybug": "master-dev"

To actually install Ladybug in your project, download the composer binary and run it:

# or
curl -O

php composer.phar install

After running the install command, you must see a new vendor directory that must contain the Ladybug code. Then, you must load ladybug helpers:

require_once __DIR__ . '/vendor/autoload.php'; // file generated by composer. Change to fit your needs


Git submodule

If you want to clone the project, you will have to execute git submodule init and git submodule update in order to download the dependencies.

Download zip file

As easy as download, include the library and use the provided helpers.

require_once 'lib/Ladybug/Autoloader.php';

// alternatively, use another PSR-0 compliant autoloader (like the Symfony2 ClassLoader
// for instance) and load the helpers manually: Ladybug\Loader::loadHelpers();



The are 5 helpers:

ladybug_dump($var1[, $var2[, ...]]): Dumps one or more variables

ladybug_dump_die($var1[, $var2[, ...]]): Dumps one or more variables and terminates the current script

ladybug_dump_return($format, $var1[, $var2[, ...]]): Dumps one or more variables and returns the dump in any of the following formats:

  • yaml: Returns the dump in YAML
  • json: Returns the dump in JSON
  • xml: Returns the dump in XML
  • php: Returns the dump in PHP arrays

ladybug_dump_ini([$extension]): Dumps all configuration options

ladybug_dump_ext(): Dumps loaded extensions

There are also some shortcuts in case you are not using this function names:

ld($var1[, $var2[, ...]]): shortcut for ladybug_dump

ldd($var1[, $var2[, ...]]): shortcut for ladybug_dump_die

ldr($format, $var1[, $var2[, ...]]): shortcut for ladybug_return


Almost any display option can be easily customizable, using the function ladybug_set($key, $value). Available options and default values:

  • general.expanded = false
  • array.max_nesting_level = 8
  • object.max_nesting_level = 3
  • object.show_data = true
  • object.show_classinfo = true
  • object.show_constants = true
  • object.show_methods = true
  • object.show_properties = true
  • = true
  • bool.html_color = '#008'
  • bool.cli_color = 'blue'
  • float.html_color = '#800'
  • float.cli_color = 'red'
  • int.html_color = '#800'
  • int.cli_color = 'red'
  • string.html_color = '#080'
  • string.cli_color = 'green'
  • string.show_quotes = true
  • string.show_quotes = '/Asset/tree.min.css'


The library is easily extensible by adding new classes in lib/Ladybug/Extension/Object and lib/Ladybug/Extension/Resource directories. These new classes will have to extend from LadybugExtension class.

For example, there is already an extension to dump the rows of a mysql resultset, in lib/Ladybug/Extension/Resource/MysqlResult.php, so once is defined, Ladybug will be able to find it and use its dump method.

If you want to add a new dumper for DateTime object, you should create a new class in lib/Ladybug/Extension/Object/Datetime.php, that will extend from LadybugExtension and will have to provide a public method called dump.

Symfony2 users

Take a look at LadybugBundle.