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
- 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
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);
Code:
$arr = ['a', 'b', 'c'];
dump($arr);
Output:
Code:
$arr = ['brand' => 'Audi', 'model' => 'A8'];
dump($arr);
Output:
Code:
class SimpleClass {
private $property;
function __construct($property) {
$this->property = $property;
}
function outputProperty() {
echo $property;
}
}
dump(new SimpleClass('value'));
Output:
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:
Code:
$xml = simplexml_load_file('XMLFile.xml');
dump($xml);
Output:
Code:
$file = fopen('file.xyz', 'r');
dump($file);
Output:
- Fixed output for the case no or tag can be found
- Added recursion detection
- Fixed styling issues
- Added output of resources (Issue #3)
- Made PHPDump the default in the example