Last active
August 29, 2015 14:12
-
-
Save fireflydev/162d19b211b478449acd to your computer and use it in GitHub Desktop.
Send PHP Debug Information to Javascript Console
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
<?php | |
/** | |
* Send PHP debug data to JS console.log | |
* Example: | |
* <code> | |
* phog(compact('table', 'id'), __FILE__); | |
* </code> | |
* | |
* Which outputs the following in the console: | |
* ===== START PHP DUMP ===== | |
* Output From /Users/jeremy/apollo/apollo/core/Admin/AdminController.php | |
* table: pages | |
* id: 9226 | |
* ===== END PHP DUMP ===== | |
* | |
* @param Array $vars Variables to dump as an associative array (compact() recommended). | |
* @param String $source Local source where phog() was called. Use __FILE__ in most circumstances. | |
* @author J.M. Usher <jeremy.usher@gmail.com> | |
* @return void | |
*/ | |
function phog(array $vars, $source) { | |
$out = array(); | |
$out[] = '===== START PHP DUMP ====='; | |
$out[] = "Output From " . $source; | |
foreach($vars as $name=>$value) { | |
$out[] = $name . ': ' . print_r($value, true); | |
} | |
$out[] = '===== END PHP DUMP ====='; | |
$out = json_encode(implode("\r\n", $out)); | |
print "<script> console.log($out); </script>"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment