-
-
Save devfabriciobr/1f72d8140769604a86b17df40753802f to your computer and use it in GitHub Desktop.
DEBUG PHP PERSONALIZADO
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 | |
| # ADICIONAR NO FINAL DO ARQUIVO init.php | |
| # EXEMPLO USO: debug($param); | |
| function debug($data) | |
| { | |
| $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); | |
| $caller = null; | |
| foreach ($backtrace as $frame) { | |
| if (isset($frame['function']) && $frame['function'] === __FUNCTION__) {continue;} | |
| if (isset($frame['file'])) { | |
| $file = $frame['file']; | |
| if (strpos($file, 'app/') !== false) {$caller = $frame;break;} | |
| if (strpos($file, 'Adianti') !== false || strpos($file,'TPage.php') !== false||strpos($file, 'AdiantiPageControlTrait.php') !== false) {continue;} | |
| } | |
| } | |
| if (!$caller && !empty($backtrace)) {$caller = $backtrace[0];} | |
| $file = $caller['file']; | |
| $line = $caller['line']; | |
| $fileName = basename($file); | |
| $titleText = is_string($data) ? "String (" . strlen($data) . " chars)" : gettype($data); | |
| $encodedData = htmlspecialchars(var_export($data,true), ENT_QUOTES,'UTF-8'); | |
| echo " | |
| <div style='font-family: monospace; margin: 10px 0; border: 1px solid #ddd; border-radius: 4px; overflow: hidden; box-shadow: 0 2px 4px rgba(0,0,0,0.1); background-color: #fff; max-width: 90vw; overflow-x: auto;'> | |
| <div style='padding: 8px 12px; background-color: #f5f5f5; font-weight: bold;'> | |
| 🔴 DEBUG: $titleText <span style='font-weight:normal; color: #666;'>($fileName, Linha: $line)</span> | |
| </div><pre style='padding: 12px; margin: 0; background-color: #f9f9f9; border-top: 1px solid #eee; white-space: pre-wrap; word-wrap: break-word; overflow-x: auto; color: #333; font-size: 13px; line-height: 1.4;'>$encodedData</pre> | |
| </div>"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment