3v4l.org

run code in 300+ PHP versions simultaneously
<?php function debug($variable) { ob_start(); var_dump($variable); $output = ob_get_clean(); $maps = [ 'string' => "/(string\((?P<length>\d+)\)) (?P<value>\"(?<!\\\).*\")/i", 'array' => "/\[\"(?P<key>.+)\"(?:\:\"(?P<class>[a-z0-9_\\\]+)\")?(?:\:(?P<scope>public|protected|private))?\]=>/Ui", 'countable' => "/(?P<type>array|int|string)\((?P<count>\d+)\)/", 'resource' => "/resource\((?P<count>\d+)\) of type \((?P<class>[a-z0-9_\\\]+)\)/", 'bool' => "/bool\((?P<value>true|false)\)/", 'float' => "/float\((?P<value>[0-9\.]+)\)/", 'object' => "/object\((?P<class>\S+)\)\#(?P<id>\d+) \((?P<count>\d+)\)/i" ]; foreach ($maps as $function => $pattern) { $output = preg_replace_callback($pattern, function ($matches) use ($function) { switch ($function) { case 'string': $matches['value'] = htmlspecialchars($matches['value']); return '<span style="color: #0000FF;">string</span>(<span style="color: #1287DB;">' . $matches['length'] . ')</span> <span style="color: #6B6E6E;">' . $matches['value'] . '</span>'; case 'array': $key = '<span style="color: #008000;">"' . $matches['key'] . '"</span>'; $class = ''; $scope = ''; if (isset($matches['class']) && !empty($matches['class'])) { $class = ':<span style="color: #4D5D94;">"' . $matches['class'] . '"</span>'; } if (isset($matches['scope']) && !empty($matches['scope'])) { $scope = ':<span style="color: #666666;">' . $matches['scope'] . '</span>'; } return '[' . $key . $class . $scope . ']=>'; case 'countable': $type = '<span style="color: #0000FF;">' . $matches['type'] . '</span>'; $count = '(<span style="color: #1287DB;">' . $matches['count'] . '</span>)'; return $type . $count; case 'bool': return '<span style="color: #0000FF;">bool</span>(<span style="color: #0000FF;">' . $matches['value'] . '</span>)'; case 'float': return '<span style="color: #0000FF;">float</span>(<span style="color: #1287DB;">' . $matches['value'] . '</span>)'; case 'resource': return '<span style="color: #0000FF;">resource</span>(<span style="color: #1287DB;">' . $matches['count'] . '</span>) of type (<span style="color: #4D5D94;">' . $matches['class'] . '</span>)'; case 'object': return '<span style="color: #0000FF;">object</span>(<span style="color: #4D5D94;">' . $matches['class'] . '</span>)#' . $matches['id'] . ' (<span style="color: #1287DB;">' . $matches['count'] . '</span>)'; } }, $output); } $header = ''; list($debugfile) = debug_backtrace(); if (!empty($debugfile['file'])) { $header = '<h4 style="border-bottom:1px solid #bbb;font-weight:bold;margin:0 0 10px 0;padding:3px 0 10px 0">' . $debugfile['file'] . '</h4>'; } echo '<pre style="background-color: #CDDCF4;border: 1px solid #bbb;border-radius: 4px;-moz-border-radius:4px;-webkit-border-radius\:4px;font-size:12px;line-height:1.4em;margin:30px;padding:7px">' . $header . $output . '</pre>'; } debug(['foo', 'bar', 'baz', 42]);
based on HqPMc
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.21, 7.4.0 - 7.4.9, 8.0.0alpha1 - beta1
<pre style="background-color: #CDDCF4;border: 1px solid #bbb;border-radius: 4px;-moz-border-radius:4px;-webkit-border-radius\:4px;font-size:12px;line-height:1.4em;margin:30px;padding:7px"><h4 style="border-bottom:1px solid #bbb;font-weight:bold;margin:0 0 10px 0;padding:3px 0 10px 0">/in/iupYJ</h4><span style="color: #0000FF;">array</span>(<span style="color: #1287DB;">4</span>) { [0]=> <span style="color: #0000FF;">string</span>(<span style="color: #1287DB;">3)</span> <span style="color: #6B6E6E;">&quot;foo&quot;</span> [1]=> <span style="color: #0000FF;">string</span>(<span style="color: #1287DB;">3)</span> <span style="color: #6B6E6E;">&quot;bar&quot;</span> [2]=> <span style="color: #0000FF;">string</span>(<span style="color: #1287DB;">3)</span> <span style="color: #6B6E6E;">&quot;baz&quot;</span> [3]=> <span style="color: #0000FF;">int</span>(<span style="color: #1287DB;">42</span>) } </pre>