I’m trying to write a simple PHP MVC framework to play with. Right now, I have some abstract classes defined in a specific file (model, view, controller), which will be “extended” by other classes I create. For example:
public my_specific_controller extends controller {
// some stuff
}
However, if I want to do this, I have to include the “main” php file with all the abstract classes every time I want to make an instance of that class. Is there a way around this? Is there a way to make this very efficient and not bogged down by the fact that I’m including this file over and over. I’m new to this side of PHP (used to doing simple things and working within existing frameworks).
You need to
includethe parent class file in the file where you declare your class, not where you instantiate it. E.g.:controller.php:
specific_controller.php;
index.php:
Autoloading can also help to reduce the
requirestatements.