Check location of a from a class called by that script PHP :s
<p>If I have a class (e.g Database) can I check the location of the script that tried to instantiate this class.</p>

<p>An example:</p>

<p>I have an example dir structure like so:</p>

<pre><code>lib
  Database.class.php
app
  action.class.php
</code></pre>

<p>and in action.class.php:</p>

<pre><code>$db = new Database;
</code></pre>

<p>and in Database.class.php</p>

<pre><code>function __construct(){
$name = //some code to find out that app/action.class.php just tried to instantiate me
$name = explode('/',$name);
if($name[0] = 'app') //allow script to use the class
else $this-&gt;__destruct; //dont allow other scripts not in app dir for example
}
</code></pre>

<p>I dont know if this is possible or not</p>

<p>Regards
Luke</p>

<p>UPDATE:  <em>It seems like this is possible but not good practice (from answers below) thank you for your time, I wont be implimenting this mainly due to @Gordons argument.</em></p>
