Last active
March 31, 2023 17:21
-
-
Save Polmonite/85d0311a844eef0544f7baecb524459b to your computer and use it in GitHub Desktop.
dump and dd functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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( | |
[ | |
'/\<\;\!\-\-begin\-\-\>\;.+?\/\*end\*\//', | |
'/\/\*begin\*\/.+?\<\;\!\-\-end\-\-\>\;/', | |
'/array\ \;\(\<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