title: How do I get the class name or filename of the object that instianiated the current object?
body: <p>To clarify:</p>
  
  <p>I'm building a Logger class that allows me to easily log messages:</p>
  
  <p>lib.Logger.php:</p>
  
  <pre><code>&lt;?php
  class Logger {
      private $handle;
  
      public function __construct($log_name, $log_path) {
  
          if ( ! is_dir($log_path))
              throw new Exception('Log path does not exist.');
  
          if ( ! in_array(strtolower(substr($log_name, 0, -4)), array('.log', '.txt')))
              $log_name = "{$log_name}.log";
  
          $this-&gt;handle = fopen("{$log_path}/{$log_name}", 'a');
  
          $this-&gt;log('------------- Initializing ------------- '.get_parent_class($this));
      }
  
      // --------------------------------------------------------------------
  
      public function __destruct() {
          fclose($this-&gt;handle);
      }
  
      // --------------------------------------------------------------------
  
      public function log($message) {
          $time = date(DATE_RFC822);
  
          $log = "[{$time}] {$message}\n";
  
          fwrite($this-&gt;handle, $log);
      }    
  
  }
  
  ?&gt;
  </code></pre>
  
  <p>And I call this using:</p>
  
  <p>MyController.php:</p>
  
  <pre><code>&lt;?php
  class MyController extends Controller {
      $logger = new Logger('testlog','/path/to/logs/');
      $logger-&gt;log('Logs are fun!');
  }
  ?&gt;
  </code></pre>
  
  <p>When I initialize the object:</p>
  
  <pre><code> $this-&gt;log('------------- Initializing ------------- '.get_parent_class($this));
  </code></pre>
  
  <p>I want to log the name of the object (or file) that is calling log() -- in this case, either <pre>MyController</pre> or <pre>/path/to/MyController.php</pre>.</p>
  
  <p>I tried using get_parent_class(), but of course this doesn't work because Logger does not have a parent class per se.</p>
  
  <p>Any ideas?  thank you so much for the help!</p>
  
  <p>Alex B</p>