logdebug and pause

I find this useful when printing out debug information in php.

#!/usr/local/bin/php
<?php
/*
 * This file presents a way to print a variable name in php while printing
 * debugging information.
 *
 * Idea from:
 * http://stackoverflow.com/questions/255312/how-to-get-a-variable-name-as-\
 * a-string-in-php
 */

function logdebug() {
  $args = func_get_args();
  $bt = debug_backtrace();
  $fileName = $bt[0]['file'];
  $src = file($fileName);
  $lineNumber = $bt[0]['line'];
  $line = $src[$lineNumber - 1];
  $function_name = __FUNCTION__;

  // let's match the function call and the last closing bracket
  preg_match( "#".$function_name."\((.+)\)#", $line, $match );
  $code = $match[1];

  $source_info = '('.$code.') @ '.$fileName.':'.$lineNumber;
  print("##########".$source_info."##########\n");
  foreach ($args as $a) {
    var_dump($a);
  }
  print("----------".$source_info."----------"."\n");
}

function pause() {
  $bt = debug_backtrace();
  $fileName = $bt[0]['file'];
  $lineNumber = $bt[0]['line'];
  print("Stopped at ".$fileName.':'.$lineNumber.
    '. Do you want to continue? (y/n): ');
  $response = fgets(STDIN);
  $response = trim($response);
  if ($response != "y" && $response != "") {
    exit(0);
  }
}