Skip to content

SebastianZ/PHPDump

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHPDump

PHP version of ColdFusion's <cfdump>.

The benefits in comparison to var_dump() are that it outputs variables in a visually appealing format and provides more information.

Differences to Josh Sherman's 'dBug' are:

  • Arrays are displayed differently depending on whether they are indexed or associative
  • Objects are displayed like in ColdFusion
  • PHPDoc info is included in object output
  • Distributed under MIT license

Features

  • Displays variables in a structured and colored format
  • Output is foldable
  • Provides advanced information on objects and resources
  • Supported variable types are: All primitive types, arrays, objects, PDO query results, SimpleXML objects, resources

Usage

You just need to include the debug.php file:

include_once 'debug.php';

When that is done you can output a variable like this:

dump($variable);

Examples

Indexed array

Code:

$arr = ['a', 'b', 'c'];
dump($arr);

Output:

Dump of an indexed array

Associative array

Code:

$arr = ['brand' => 'Audi', 'model' => 'A8'];
dump($arr);

Output:

Dump of an associative array

Object

Code:

class SimpleClass {
  private $property;

  function __construct($property) {
    $this->property = $property;
  }

  function outputProperty() {
    echo $property;
  }
}

dump(new SimpleClass('value'));

Output:

Dump of an object

Database query result (PDO)

Code:

$db = new PDO('pgsql:host=localhost;dbname=mydb', 'user', 'password');
$select = $db->prepare('SELECT *
                        FROM persons
                        WHERE LastName LIKE :LastName
                        ORDER BY LastName ASC');
$select->execute([':LastName' => 'M%']);

dump($select);

Output:

Dump of a query result

XML (SimpleXML)

Code:

$xml = simplexml_load_file('XMLFile.xml');
dump($xml);

Output:

Dump of an XML

Resources

Code:

$file = fopen('file.xyz', 'r');
dump($file);

Output:

Dump of a resource

Version history

0.4

  • Fixed output for the case no or tag can be found
  • Added recursion detection
  • Fixed styling issues

0.3

  • Added output of resources (Issue #3)
  • Made PHPDump the default in the example

0.2

  • Added output folding (Issue #2)
  • Removed need to add endOutput(); at the end of the script (Issue #1)

0.1 Initial version

About

PHP version of ColdFusion's <cfdump>

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages