michel/vardumper

Zero-dependency PHP debug library. Drop it in any project — no framework required.

Maintainers

Package info

git.depohub.org/michel/vardumper

pkg:composer/michel/vardumper

Transparency log

Statistics

Installs: 7

Dependents: 1

Suggesters: 0

1.1.0 2026-07-15 09:14 UTC

This package is not auto-updated.

Last update: 2026-07-15 09:57:23 UTC


README

Zero-dependency PHP debug library. Drop it in any project — no framework required.

Philosophy: one function call → one clear output. Nothing hidden, nothing magic.

Install

composer require michel/vardumper

Requirements: PHP ≥ 7.4 · ext-json (bundled with PHP by default)

Auto-detects the environment: HTML output in the browser, plain text in the terminal.

Functions

dump() — inspect without stopping

Prints the variable. Script keeps running.

$user = ['name' => 'Alice', 'age' => 30, 'active' => true];
dump($user);

Browser output (styled HTML, collapsible):

array(3) (
  "name"   => string "Alice"  (Length: 5)
  "age"    => int 30
  "active" => bool true
)

Terminal output:

array(3) [
  [name]   => (string) "Alice"
  [age]    => (int) 30
  [active] => (bool) true
]

Multiple variables in one call:

dump($request, $user, $token);
// → prints each one, in order, script continues

dd() — inspect and stop

Same as dump() but exits the script immediately after. Nothing runs after this line.

$result = computePrice($cart);
dd($result);
// → dumps $result, then exit(1). Code below never runs.

btrace() — show the call stack

Prints the last N function calls that led to the current line. Use it when you need to understand how the code reached a specific point.

function processOrder($order) {
    btrace(); // → shows the last 5 calls that led here
    // ...
}

Output (HTML or terminal):

Backtrace — last 5 call(s)

#1 - handleRequest: Called from index.php:12
#2 - dispatch:      Called from Router.php:45
#3 - processOrder:  Called from OrderController.php:88
...

Limit the depth:

btrace(3); // show only the last 3 calls
btrace(1); // show only the direct caller

dd_bt() — backtrace + dump + stop

Combines btrace() and dd() in one call. Step 1: shows the call stack. Step 2: dumps the value. Step 3: stops the script.

Use it when you want both where and what at the same time.

$price = computePrice($cart);
dd_bt($price);
// → prints the call stack
// → dumps $price
// → exit(1)

Limit backtrace depth:

dd_bt($price, backtraceLimit: 3);

console_log() — dump to the browser console

Injects the variable into the browser's JavaScript console as a console.log(). The page HTML is not altered. The script keeps running.

Use it when:

  • you are debugging an API / JSON response (adding HTML would break the output)
  • you want to debug in production without touching the page
  • you need to dump something without stopping the request
$response = buildApiResponse($data);
console_log($response);
// → page stays clean
// → open DevTools (F12) → Console tab
// → you see: [VarDumper] → controller.php:42
//              "Array\n(\n    [status] => ok ...\n)"

Multiple values:

console_log($request, $user, $token);
// → three separate console.log() blocks, each labelled with its file:line

Works for any PHP type — arrays, objects (including private properties), scalars. Uses print_r() internally, not json_encode(), so objects are fully represented.

What gets dumped — type coverage

PHP typeWhat you see
stringstring "hello" (Length: 5)
intint 42
floatfloat 3.14
boolbool true
nullnull
arrayrecursive tree, collapsible in HTML
objectclass name + object id + all properties (public, protected, private, traits, parent)
resourceresource(stream)
Circular ref[Circular: ClassName#42] — no stackoverflow

Object depth is limited to 5 levels by default (configurable).

Custom output — advanced usage

Every class implements OutputInterface. You can inject your own renderer.

use Michel\Debug\VarDumper;
use Michel\Debug\Output\OutputInterface;

class LogOutput implements OutputInterface
{
    public function print($value): void
    {
        // send to a log file, a Slack webhook, anywhere
        file_put_contents('/tmp/debug.log', print_r($value, true) . PHP_EOL, FILE_APPEND);
    }
}

$dumper = new VarDumper(new LogOutput());
$dumper->dump($myVariable);

Built-in outputs you can use directly:

ClassWhen to use
HtmlOutputBrowser (default)
CliPrintOutputTerminal, formatted (default in CLI)
CliVarDumpOutputTerminal, raw var_dump() style
ConsoleLogOutputBrowser JS console

License

MIT — see LICENSE