Skip to content

Instantly share code, notes, and snippets.

@fireflydev
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fireflydev/162d19b211b478449acd to your computer and use it in GitHub Desktop.
Save fireflydev/162d19b211b478449acd to your computer and use it in GitHub Desktop.
Send PHP Debug Information to Javascript Console
<?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