Mathieu Hays

Because I required to be able to dump data without altering the design of a website I came with this snippet that enable me to render php variables to the browser’s console. It basically just support numbers, string, arrays and simple stdClass objects which I think is enough for most use cases.

function console_log()
  $log = array();

  foreach (func_get_args() as $arg) {
    if (is_object($arg)) {
      $_arg = get_object_vars($_arg);

    $log[] = json_encode($_arg);
  echo "<script type='text/javascript'>console.log(".join(",", $log).")</script>";

Let me know what you think in the comments 😉