Last active
October 4, 2015 20:28
-
-
Save Robdebert/2694069 to your computer and use it in GitHub Desktop.
Debugging-Output for PHP. Simple Usage
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
/** | |
* Simple Usage: preprint($mixed) will output everything, that can be outputtet by PHP in a formatted way using the html pre-tag. | |
* You can use __FILE__.__LINE__ as second parameter, to see, where the ouput was generated | |
* | |
* I always include this function in all of my projects because i output a lot of debugging-data. And i don't want to write those html tags everytime :-) | |
* | |
* @author: Robert Heine | |
* @link: www.joomla-jquery-internet.de | |
* @changes: RH, 21.08.2014: Ergänzung um den Backtrace, was $where überflüßig macht. | |
* RH, 29.05.2015: Ergänzung wegen ENVIRONMENT. Soll NUR im DEV-Modus etwas ausgeben. | |
**/ | |
if( !function_exists("preprint")) { | |
function preprint($s, $where="") { | |
/**** das hier NIE löschen! **** | |
* Manchmal werden im Code preprint-Ausgaben vergessen, das hier sorgt dafür dass die Live- und Test-Seite funktioniert. | |
* | |
* Stattdessen in index.php oder defines.php die ENV-Abfrage anpassen. | |
**/ | |
if (ENVIRONMENT!="development") return; | |
if (!empty($where)) $where = " -- Datei: ".str_replace($_SERVER["DOCUMENT_ROOT"], "", $where); | |
print "<style type='text/css'>pre { font-size: 12px; font-family: courier; } </style>"; | |
print "<pre><small>".ENVIRONMENT."-System PREPRINT-Ausgabe".$where."</small>\n<strong>"; | |
print_r($s); | |
print "</strong></pre>"; | |
if (empty($where)) { | |
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); | |
print "<pre>BACKTRACE: ".print_r($trace[1], 1)."</pre><br/><br/>"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment