Last active
May 31, 2018 04:55
-
-
Save ethaizone/31788d00f09b22f47bb9d712ee4ea9b1 to your computer and use it in GitHub Desktop.
[PHP] Dump collection.
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 | |
/** | |
* Dump collection. For who can't set breakpoint in their project. | |
* | |
* By EThaiZone | |
*/ | |
if (! function_exists('jd')) { | |
/** | |
* Dump and json and exit | |
*/ | |
function jd() | |
{ | |
header('Content-Type: application/json'); | |
echo json_encode(func_get_args()); | |
exit; | |
} | |
} | |
if (! function_exists('d')) { | |
/** | |
* Dump as var_dump | |
*/ | |
function d() | |
{ | |
call_user_func_array('var_dump', func_get_args()); | |
} | |
} | |
if (! function_exists('dd')) { | |
/** | |
* var_dump and exit | |
*/ | |
function dd() | |
{ | |
header('Content-Type: text/html'); | |
call_user_func_array('d', func_get_args()); | |
exit; | |
} | |
} | |
if (! function_exists('sd')) { | |
/** | |
* echo and exit | |
*/ | |
function sd() | |
{ | |
header('Content-Type: text/html'); | |
foreach(func_get_args() as $v) { | |
if(is_string($v)) { | |
echo $v; | |
} elseif (is_array($v)) { | |
echo "<pre>".print_r((array) $v, true); | |
} else { | |
var_dump($v); | |
} | |
} | |
exit; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment