If I have a class (e.g Database) can I check the location of the script that tried to instantiate this class.
An example:
I have an example dir structure like so:
lib
Database.class.php
app
action.class.php
and in action.class.php:
$db = new Database;
and in Database.class.php
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->__destruct; //dont allow other scripts not in app dir for example
}
I dont know if this is possible or not
Regards Luke
UPDATE: 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.