Created
January 21, 2017 05:34
-
-
Save soubhikchatterjee/98fdcb027db34454778d8f8682a4e606 to your computer and use it in GitHub Desktop.
Quick Debugging Functions for your PHP Application
This file contains 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
/** | |
* Print with formatting and Die. Used for debugging purpose. | |
* | |
* @author Soubhik Chatterjee | |
* @param string $text | |
* @param string $label | |
*/ | |
function prd($text = '', $label = ''){ | |
echo '<pre>',"\n"; | |
echo '==', $label, '==', "\n"; | |
print_r($text); | |
echo "\n",'</pre>', "\n\n"; | |
exit; | |
} | |
/** | |
* Short function for print_r() with formatting. Used for debugging purpose. | |
* | |
* @author Soubhik Chatterjee | |
* @param string $text | |
* @param string $label | |
*/ | |
function pr($text, $label = ''){ | |
echo '<pre>',"\n"; | |
echo '==', $label, '==', "\n"; | |
print_r($text); | |
echo "\n",'</pre>', "\n\n"; | |
} | |
/** | |
* Prints all specified arguments with their variable name | |
* | |
* @author Soubhik Chatterjee | |
* | |
* @param ... | |
*/ | |
function pra() | |
{ | |
$args = func_get_args(); | |
if (_is_array($args)) { | |
$counter = 1; | |
foreach ($args as $val) { | |
pr($val, $counter); | |
$counter++; | |
} | |
} | |
} | |
/** | |
* Prints all specified arguments with their variable name and exits | |
* | |
* @author Soubhik Chatterjee | |
* | |
* @param ... | |
*/ | |
function prad() | |
{ | |
$args = func_get_args(); | |
if (_is_array($args)) { | |
$counter = 1; | |
foreach ($args as $val) { | |
pr($val, $counter); | |
$counter++; | |
} | |
} | |
exit; | |
} | |
/** | |
* var dumps and dies | |
* | |
* @author Soubhik Chatterjee | |
* @param string $text | |
* @param string $label | |
*/ | |
function vd($text, $label = ''){ | |
echo '<pre>',"\n"; | |
echo '==', $label, '==', "\n"; | |
var_dump($text); | |
echo "\n",'</pre>', "\n\n"; | |
} | |
/** | |
* var dumps and dies | |
* | |
* @author Soubhik Chatterjee | |
* @param string $text | |
* @param string $label | |
*/ | |
function vdd($text, $label = ''){ | |
echo '<pre>',"\n"; | |
echo '==', $label, '==', "\n"; | |
var_dump($text); | |
echo "\n",'</pre>', "\n\n"; | |
exit; | |
} | |
/** | |
* Logs any data | |
* | |
* @author Soubhik Chatterjee | |
* @param mixed $data | |
* @param string $label | |
*/ | |
function logg($data, $label = '') { | |
$file = '/Users/soubhik/Documents/tmp/my-errors.log'; | |
error_log('========' . $label . '========' . "\n", 3, $file); | |
error_log(json_encode($data) . "\n", 3, $file); | |
error_log( '========' . $label . '========'. "\n\n", 3, $file); | |
} | |
/** | |
* @author Soubhik Chatterjee <[email protected]> | |
* @param mixed $data | |
* @return string | |
*/ | |
function pt($data) | |
{ | |
if (is_object($data)) { | |
echo get_class($data); | |
} else if (is_bool($data)) { | |
var_dump($data); | |
} else if (is_array($data)) { | |
pr($data); | |
} else { | |
echo $data . ' [' . gettype($data) . ']'; | |
} | |
} | |
/** | |
* @author Soubhik Chatterjee <[email protected]> | |
* @param mixed $data | |
* @return string | |
*/ | |
function ptd($data) | |
{ | |
if (is_object($data)) { | |
echo get_class($data); | |
} else if (is_bool($data)) { | |
var_dump($data); | |
} else if (is_array($data)) { | |
pr($data); | |
} else { | |
echo $data . ' [' . gettype($data) . ']'; | |
} | |
exit(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment