Skip to content

Instantly share code, notes, and snippets.

@Polmonite
Last active March 31, 2023 17:21
Show Gist options
  • Save Polmonite/85d0311a844eef0544f7baecb524459b to your computer and use it in GitHub Desktop.
Save Polmonite/85d0311a844eef0544f7baecb524459b to your computer and use it in GitHub Desktop.
dump and dd functions
<?php
if (!function_exists('dump')) {
function dump(...$args)
{
$message = implode(
"\n\n",
array_map(
function($value) {
return var_export($value, true);
},
$args
)
);
$is_cli = in_array(php_sapi_name(), [ 'cli', 'cli-server' ]);
if (!$is_cli) {
$message = preg_replace(
[
'/\&lt\;\!\-\-begin\-\-\&gt\;.+?\/\*end\*\//',
'/\/\*begin\*\/.+?\&lt\;\!\-\-end\-\-\&gt\;/',
'/array\&nbsp\;\(\<br\s\/\>\)/',
],
[
'',
'',
'array ( )',
],
highlight_string(
"<!--begin--><?php/*end*/\n"
. $message
. "\n/*begin*/?><!--end-->\n\n",
true
)
);
}
echo $message;
}
}
if (!function_exists('dd')) {
function dd(...$args)
{
dump(...$args);
die();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment