PHP function: find argument's variable name, and function calls line number
<p>I want to do something like this for simplifying logging operations. Any idea what I should put in for <code>?[1]?</code> and <code>?[2]?</code>?</p>

<pre><code>function log_var($var) {
  $line = ?[1]?;
  $var_name = ?[2]?;

  $line--;

  $filepath = 'log-' . date('Y-m-d'). '.txt';
  $message  = "$line, $var_name = $var\n";
  $fp = fopen($filepath, "a");
  fwrite($fp, $message);
  fclose($fp);
  @chmod($filepath, 0666);
  return TRUE;
}
</code></pre>

<p>This how I'd use the function in code (numbers are assumed to be line numbers in actual code):</p>

<pre><code>23  $a = 'hello';
24  log_var($a);
25  $b = 'bye';
26  log_var($b);
</code></pre>

<p>And this is what I want to be written to the log file:</p>

<pre><code>23, a = hello
25, b = bye
</code></pre>

<p><strong>EDIT</strong>
I converted Paul Dixon function a bit and added the result as an answer. The new form does even MORE than I originally hoped for. Thank you again guys!</p>
