title: Get code line and file that's executing the current function in PHP?
body: <p>Imagine I have the following situation:</p>
  
  <p>File1.php</p>
  
  <pre><code>&lt;?php
   include("Function.php");
   log("test");
  ?&gt;
  </code></pre>
  
  <p>Function.php</p>
  
  <pre><code>&lt;?php
   function log($msg)
   {
    echo "";
   }
  ?&gt;
  </code></pre>
  
  <p>I want to change the log function so that it would produce the following:</p>
  
  <blockquote>
    <p>test (file: File1.php, line number: 3)</p>
  </blockquote>
  
  <p>So, any way to get the file name and the line number of the code that executed the current function in PHP?</p>
  
  <p><strong>EDIT for backlog usage comments:</strong>
  When I use backlog in my object oriented way of programming I have the following situation.</p>
  
  <p>Index.php</p>
  
  <pre><code>&lt;?php
   include("Logger.static.php");
   include("TestClass.class.php");
   new TestClass();
  ?&gt;
  </code></pre>
  
  <p>TestClass.class.php</p>
  
  <pre><code>&lt;?php
   class TestClass
   {
     function __construct()
     {
       Logger::log("this is a test log message");
     }
   }
  ?&gt;
  </code></pre>
  
  <p>Logger.static.php</p>
  
  <pre><code>&lt;?php
   class Logger
   {
     static public function log($msg)
     {
       $bt = debug_backtrace();
       $caller = array_shift($bt);
       echo $caller['file'];
       echo $caller['line'];
     }
   }
  ?&gt;
  </code></pre>
  
  <p>This example will return as file "Index.php" and as line number 4, this is where the class is initiated. However, it is supposed to return the file TestClass.class.php and line number 6. Any idea how to fix this?</p>