while making a module system for my CMS I stumbled upon a problem that I wish to solve in a better way (if possible).
I've got an abstract class (simplified):
abstract class aModule {
function __construct() {
include(dirname(__FILE__).'/resources/content.php');
}
}
What I expected to happen when I instantiate child of this class, for example:
class SomeModule extends aModule {
}
$sm = new SomeModule();
Is for FILE constant to be location of SomeModule class file but instead it takes parent's, and ofcourse include doesn't work. *Note: both class files are included from external ModuleManager engine so it isn't possible for me to use $_SERVER['SCRIPT_FILENAME'].
I solved the problem the ugly way, I made abstract class constructor like this:
function __construct($fileLoc) {
include(dirname($fileLoc).'/resources/content.php');
}
So for module to work I need to make it have constructor on its own:
function __construct() {
parent::__construct(__FILE__);
}
This forces anyone who makes modules to include this exact constructor in his module class definition and as far as I learned, any repetition in programming is bad.
So,is there a way that my abstract class can know child classes file location or is this the only way to do it ?