title: find caller script path from a library
body: <p>When execution a script that includes a library, I whant to find from whithin the library the caller script, in Perl I'm using env: <code>$0</code> that gives me the path to the caller script. In PHP <code>__FILE__</code> gives me the current script, so in the library it gives me the library path not the caller script path.</p>
  
  <p>from perl documentation: <strong>$0 Contains the name of the file containing the Perl script being executed.</strong> </p>
  
  <p>I think It can be done using debug_backtrace(), but there is another better/shorter method ?</p>
  
  <p><strong>EDIT:</strong>   (added sample code)  </p>
  
  <p>file: index.php</p>
  
  <pre><code>&lt;?php
  require 'locallib.php';
  echo 'in original script = '.__FILE__.'&lt;br /&gt;';
  ?&gt;
  </code></pre>
  
  <p>file: locallib.php</p>
  
  <pre><code>&lt;?php
  require "lib.php";
  echo 'in library "'.__FILE__.'"&lt;br /&gt;';
  ?&gt;
  </code></pre>
  
  <p>file: lib.php</p>
  
  <pre><code>&lt;?php
  if( $_SERVER['SCRIPT_FILENAME'] != '/var/www/html/index.php')
  {
      echo "Not allowed";exit;
  } else 
  {
      echo 'in library "'.__FILE__.'"&lt;br /&gt;';
      echo '&lt;pre&gt;';
      print_r($_SERVER);
      echo '&lt;/pre&gt;';
  }
  ?&gt;
  </code></pre>