Ladybug allows dumpling any variable, including arrays, objects and resources. Just provide a variable and Ladybug will take care of the rest:
<?php
$var1 = NULL;
$var2 = 15;
$var3 = 15.5;
$var4 = 'hello world!';
$var5 = false;
ladybug_dump($var1, $var2, $var3, $var4, $var5);
As a result:
<?php
$var = array(
array(
'name' => 'Raul',
'age' => 29
),
array(
'name' => 'John',
'age' => 27
)
);
ladybug_dump($var)
<?php
$var = new Foo();
ladybug_dump($var)
<?php
$fh = fopen('test.txt', 'r');
ladybug_dump($fh)
Ladybug is able to detect being used (e.g. browser, CLI or an ajax request) and chooses the right format:
- Browser -> Html
- CLI -> Console
- Ajax -> Text
$ php examples/array.php
array(2)
[0]: array(2)
[name]: string(4) "Raul"
[age]: int 29
[1]: array(2)
[name]: string(4) "John"
[age]: int 27
Variable dumps can be exported to some other formats, like XML, JSON or YAML, but for this,
Ladybug needs other packages to do the job: jms/serializer(for XML and JSON) and
symfony/yaml` (for YAML):
<?php
$var = 1;
$dumper = new \Ladybug\Dumper();
$dumper->setFormat('json');
$json = $dumper->dump($var);
Ladybug allows extending any object or resource to display richer information.
For example, the ladybug-plugin-extra
package provides built-in inspectors for
MySQL resultsets or GD images:
<?php
$connection = mysql_connect('localhost', 'dbuser', 'dbpassword');
mysql_select_db('dbname', $connection);
$result = mysql_query('SELECT * FROM user', $connection);
ladybug_dump($result);
<?php
$img = imagecreatefrompng(__DIR__ . '/images/ladybug.png');
ladybug_dump($img);
New inspectors can be added easily, see the extending section for more info.
Ladybug also detects automatically some classes to display an icon and a link to the documentation. For example, provides built-in support for PHP objects and Symfony2 classes:
There are lots of examples in the /examples directory.
Next section: Usage.