var_dump

var_dump(mixed ...$values): void

Dumps type, length and value of one or more variables — the most precise debug dump.

C C23

C23
#include <stdio.h>

/* no reflection: print type name and value by hand per call site */
struct User {
    const char *name;
    int scores[2];
};

int main(void) {
    printf("int %d\n", 1);
    printf("char[4] \"%s\"\n", "abc"); // includes the terminating NUL
    printf("double %g\n", 1.5);
    printf("_Bool %d\n", 1);

    int a[3] = {1, 2, 3};
    printf("int[3] [%d, %d, %d]\n", a[0], a[1], a[2]); // arrays decay to pointers: dump element-wise

    struct User u = {"Alice", {90, 85}};
    printf("struct User {name: \"%s\", scores: [%d, %d]}\n", u.name, u.scores[0], u.scores[1]);
    return 0;
}
Output
int 1
char[4] "abc"
double 1.5
_Bool 1
int[3] [1, 2, 3]
struct User {name: "Alice", scores: [90, 85]}

C++ C++26

C++26
#include <iostream>
#include <string>
#include <vector>

struct User {
    std::string name;
    std::vector<int> scores;
};

int main() {
    std::cout << "int " << 1 << "\n";
    std::cout << "string(3) \"abc\"\n"; // typeid().name() is compiler-mangled, so names are hand-written
    std::cout << "double " << 1.5 << "\n";
    std::cout << "bool " << true << "\n"; // default prints 1, need std::boolalpha for "true"

    std::vector<int> a{1, 2, 3};
    std::cout << "vector<int> size=" << a.size() << " [";
    for (size_t i = 0; i < a.size(); ++i) {
        if (i > 0) std::cout << ", ";
        std::cout << a[i];
    }
    std::cout << "]\n";

    User u{"Alice", {90, 85}};
    std::cout << "User {name: \"" << u.name << "\", scores: [" << u.scores[0] << ", " << u.scores[1] << "]}\n";
    return 0;
}
Output
int 1
string(3) "abc"
double 1.5
bool 1
vector<int> size=3 [1, 2, 3]
User {name: "Alice", scores: [90, 85]}

C# v11.0.100

v11.0.100
using System;
using System.Text.Json;

object?[] values = { 1, "abc", 1.5, true, null };
foreach (object? v in values)
{
    string type = v == null ? "null" : v.GetType().Name; // boxed: Int32/Double, not keyword names
    Console.WriteLine($"{type} {v?.ToString() ?? "null"}");
}

int[] a = { 1, 2, 3 };
Console.WriteLine($"{a.GetType().Name} [{string.Join(", ", a)}]");

var user = new User("Alice", new[] { 90, 85 });
Console.WriteLine($"{user.GetType().Name} {user}"); // record ToString keeps the nested array collapsed
Console.WriteLine($"{user.GetType().Name} {JsonSerializer.Serialize(user)}"); // JSON expands every level

public record User(string Name, int[] Scores);
Output
Int32 1
String abc
Double 1.5
Boolean True
null null
Int32[] [1, 2, 3]
User User { Name = Alice, Scores = System.Int32[] }
User {"Name":"Alice","Scores":[90,85]}

Go v1.27.4

v1.27.4
package main

import "fmt"

type User struct {
	Name   string
	Scores []int
}

func main() {
	for _, v := range []any{1, "abc", 1.5, true, nil} {
		fmt.Printf("%T %v\n", v, v) // %T prints the dynamic type
	}

	a := []int{1, 2, 3}
	fmt.Printf("%T %#v\n", a, a) // %#v prints a Go-syntax literal

	m := map[string]any{"name": "Alice", "age": 30} // fmt sorts map keys, so the output is stable
	fmt.Printf("%T %#v\n", m, m)

	u := User{Name: "Alice", Scores: []int{90, 85}}
	fmt.Printf("%T %+v\n", u, u) // %+v: fields with names
	fmt.Printf("%T %#v\n", u, u) // %#v: a Go-syntax literal
}
Output
int 1
string abc
float64 1.5
bool true
<nil> <nil>
[]int []int{1, 2, 3}
map[string]interface {} map[string]interface {}{"age":30, "name":"Alice"}
main.User {Name:Alice Scores:[90 85]}
main.User main.User{Name:"Alice", Scores:[]int{90, 85}}

Java v27.0.1

v27.0.1
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class Main {
    record User(String name, List<Integer> scores) {}

    public static void main(String[] args) {
        Object[] values = {1, "abc", 1.5, true, null};
        for (Object v : values) {
            String type = v == null ? "null" : v.getClass().getSimpleName(); // null.getClass() would NPE
            System.out.println(type + " " + v);
        }

        int[] a = {1, 2, 3};
        System.out.println("int[] " + Arrays.toString(a)); // plain toString prints [I@1b6d3586-style hash

        Map<String, Object> m = new LinkedHashMap<>();
        m.put("name", "Alice");
        m.put("age", 30);
        System.out.println(m);

        User user = new User("Alice", List.of(90, 85));
        System.out.println(user); // record auto-generates a field-expanding toString
    }
}
Output
Integer 1
String abc
Double 1.5
Boolean true
null null
int[] [1, 2, 3]
{name=Alice, age=30}
User[name=Alice, scores=[90, 85]]

JavaScript v26.13.1

v26.13.1
for (const v of [1, "abc", 1.5, true, null]) {
  console.log(typeof v, JSON.stringify(v));
}

const a = [1, 2, 3];
console.log(typeof a, a); // Node prints util.inspect form; browsers fold it, click to expand
console.log(typeof a, JSON.stringify(a));

const user = { name: "Alice", scores: [90, 85] };
console.log(user); // the "log the object, inspect it in the console" idiom
console.log(JSON.stringify(user)); // compact form, log-file friendly
Output
number 1
string "abc"
number 1.5
boolean true
object null
object [ 1, 2, 3 ]
object [1,2,3]
{ name: 'Alice', scores: [ 90, 85 ] }
{"name":"Alice","scores":[90,85]}

PHP v8.6.0

v8.6.0
var_dump(1, "abc", 1.5, true, null);

var_dump([1, 2, 3]);

var_dump(["name" => "Alice", "age" => 30]);

$u = new stdClass();
$u->name = "Alice";
$u->scores = [90, 85];
var_dump($u);
Output
int(1)
string(3) "abc"
float(1.5)
bool(true)
NULL
array(3) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
}
array(2) {
  ["name"]=>
  string(5) "Alice"
  ["age"]=>
  int(30)
}
object(stdClass)#1 (2) {
  ["name"]=>
  string(5) "Alice"
  ["scores"]=>
  array(2) {
    [0]=>
    int(90)
    [1]=>
    int(85)
  }
}

Python v3.15.2

v3.15.2
from dataclasses import dataclass

for v in (1, "abc", 1.5, True, None):
    print(type(v).__name__, repr(v))

a = [1, 2, 3]
print(type(a).__name__, repr(a))

d = {"name": "Alice", "age": 30}
print(type(d).__name__, repr(d))

@dataclass
class User:
    name: str
    scores: list

u = User("Alice", [90, 85])
print(type(u).__name__, repr(u)) # dataclass repr expands all fields
print(type(u).__name__, vars(u)) # vars() dumps the instance __dict__
Output
int 1
str 'abc'
float 1.5
bool True
NoneType None
list [1, 2, 3]
dict {'name': 'Alice', 'age': 30}
User User(name='Alice', scores=[90, 85])
User {'name': 'Alice', 'scores': [90, 85]}

Rust v1.99.1

v1.99.1
use std::any::type_name;
use std::collections::BTreeMap;
use std::fmt::Debug;

fn dump<T: Debug>(v: T) {
    println!("{} {:?}", type_name::<T>(), v);
}

#[derive(Debug)]
struct User {
    name: String,
    scores: Vec<i32>,
}

fn main() {
    dump(1);     // i32 by default
    dump("abc"); // &str
    dump(1.5);   // f64
    dump(true);  // bool

    dump(vec![1, 2, 3]);
    dump(BTreeMap::from([("age", "30"), ("name", "Alice")])); // BTreeMap sorts keys; HashMap order is unspecified
    dump(User { name: "Alice".into(), scores: vec![90, 85] });
}
Output
i32 1
&str "abc"
f64 1.5
bool true
alloc::vec::Vec<i32> [1, 2, 3]
alloc::collections::btree::map::BTreeMap<&str, &str> {"age": "30", "name": "Alice"}
main::User User { name: "Alice", scores: [90, 85] }

TypeScript v26.13.1

v26.13.1
const values: unknown[] = [1, "abc", 1.5, true, null];
for (const v of values) {
  console.log(typeof v, JSON.stringify(v));
}

const a: number[] = [1, 2, 3];
console.log(typeof a, JSON.stringify(a)); // typeof still says "object": types exist only at compile time

interface User {
  name: string;
  scores: number[];
}

const user: User = { name: "Alice", scores: [90, 85] };
console.log(user); // runtime value; Node prints it, browsers fold it
console.log(JSON.stringify(user));
Output
number 1
string "abc"
number 1.5
boolean true
object null
object [1,2,3]
{ name: 'Alice', scores: [ 90, 85 ] }
{"name":"Alice","scores":[90,85]}

Language differences

C: no reflection — arrays element-wise and structs field-by-field via hand-written printf; type names are all manual.

C++: no reflection either — the idioms are an operator<< overload for the type or hand-written field-by-field output; typeid(x).name() is an unreadable mangled name.

C#: arrays are Int32[]; a record auto-generates ToString but nested arrays only show the type name (System.Int32[]) — expanding every level needs JSON serialization.

Go: structured dumping is built in — %#v prints a Go-syntax literal (with types), %+v adds field names; maps print in sorted key order (Go 1.12+), so output is stable.

Java: arrays need Arrays.toString (a bare toString gives hash soup like [I@1b6d3586); records auto-generate a field-expanding toString, plain classes need their own.

JavaScript: typeof says object for both arrays and objects; Node's console.log prints them expanded (browsers fold by default, click to inspect), while JSON.stringify is the compact form.

PHP: var_dump's soul is exactly structured data — arrays get array(n) plus per-element type annotations, objects get class name and id (object(stdClass)#1), and nesting is expanded fully, precise down to each element's type and length.

Python: repr works out of the box for list/dict and recurses; custom classes join in by defining __repr__ (dataclasses auto-generate it), and vars() inspects a plain instance's fields.

Rust: #[derive(Debug)] + {:?} dumps Vec/BTreeMap/structs directly; type_name prints the full type path too (e.g. alloc::vec::Vec<i32>); pick BTreeMap when key order must be stable (HashMap order is unspecified).

TypeScript: same as JS — types exist only at compile time; what gets printed are runtime JS values.