@stratos said:
@morbiuswilters said:
For the loading solution, there's an even easier way: register your own autoloader and have that called. Then instead of using class_exists, just keep a static array of loaded files and check against that. That should be faster than doing class_exists(). The autoload lets you get rid of circular dependencies by stripping all require or require_once code out of everything but the autoloader. Then the load method is only called when an undefined class is encountered during execution. This also makes using code easier: just use the class and don't worry where it is included.
This is what all the cool kids are doing. It's fast, it works, and by god it's cacheble. File operations aren't cheap you know, 5 cents to the platter.
I've played with the class autoloader before, but I had problems figuring out a sane way to find the right class. Say my library is spread over multiple folders and subfolders... would I have to scan that entire mess to find the one file I need or should I encode my classes with some sort of hungarian notation? ( mClassName for model, cClassName for controller, etc).
Also what if for some stupid reason you have two classes both called the samething ( sucks but not unheard of for very large projects ). Even worse is losing a dependancy record in your code, "This construct came from this file" and then its nice to embed a tiny bit of documentation by directory structure. models/users/admin.controller.php for instance... I know this is a data interface for administrative users just by looking at the path. Sure you can work around the initial costs by dumping a class:filepath in memcache, but isn't it easier to just include/require the files you need?