var_dump and VarDumper

var_dump, print_r and Symfony VarDumper

var_dump() (Subsection 4.2.5) shows every type and length, print_r() is shorter but hides types, and var_export() prints valid PHP. Symfony VarDumper 7,425 (composer require --dev symfony/var-dumper, 8.1.7, github.com/symfony/var-dumper (https://github.com/symfony/var-dumper 7,425 )) adds dump() and dd() ("dump and die"): a collapsible tree in the browser, plain text in the CLI, object handles (#2), visibility markers (+ public) and safe handling of recursion.

print_r against VarDumper (dump.php)PHP
<?php
require __DIR__ . '/vendor/autoload.php';
echo print_r(['tags' => null, 'note' => '', 'stock' => 0], true);   // null and '' look alike
dump(new Acme\Shop\Product('BK-SQL-02', 'Indexing Deep Dive', 2900));    // Symfony VarDumper
Output
Array
(
    [tags] => 
    [note] => 
    [stock] => 0
)
Acme\Shop\Product {#2
  +sku: "BK-SQL-02"
  +title: "Indexing Deep Dive"
  +priceCents: 2900
  +stock: 0
}

print_r() made null and '' identical, the classic way print debugging misleads. For web requests, run vendor/bin/var-dump-server and set VAR_DUMPER_FORMAT=server, so dumps go to that terminal instead of into the page. Subsection 4.21.9 catches dumps left in code.