diff --git a/src/Symfony/Component/VarDumper/Resources/functions/dump.php b/src/Symfony/Component/VarDumper/Resources/functions/dump.php index e6ade0dfaed38..6bd741ea8bcac 100644 --- a/src/Symfony/Component/VarDumper/Resources/functions/dump.php +++ b/src/Symfony/Component/VarDumper/Resources/functions/dump.php @@ -66,3 +66,34 @@ function dd(mixed ...$vars): never exit(1); } } + +if (!function_exists('ddh')) { + function ddh(mixed ...$vars): never + { + if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) && !headers_sent()) { + header('HTTP/1.1 500 Internal Server Error'); + + // CORS for SPA apps like. + header("Access-Control-Allow-Origin: " . $_SERVER['HTTP_ORIGIN'] ?? '*'); + header('Access-Control-Allow-Methods: *'); + header('Access-Control-Allow-Headers: *'); + header('Access-Control-Allow-Credentials: true'); + } + + if (!$vars) { + VarDumper::dump(new ScalarStub('🐛')); + + exit(1); + } + + if (array_key_exists(0, $vars) && 1 === count($vars)) { + VarDumper::dump($vars[0]); + } else { + foreach ($vars as $k => $v) { + VarDumper::dump($v, is_int($k) ? 1 + $k : $k); + } + } + + exit(1); + } +}