views:

211

answers:

2

I'm working with a number of 'helper' classes, which affectively have a bunch of static functions which allow the controllers and actions have access to chunks of shared functionality.

Problem is that these files have been used as a dumping ground for any functionality which is required across the modules/application and as a result they are > 3k lines in size and at the top they've got about 50 require_once declarations!

Obviously if a view in the application wan't to use a small part of the functionality available from these helpers it inherits all the required files, and you end up bloating your app.

If I were to include the files on a per need basis, I could end up making numerous require_once calls to the required files, which has it's own overhead (compounded with frequency), when I need use a large amount of the functionality available from these helper files.

So essentially my question is where is the balance struck and is there a best practice that one can employ?

Thanks,

Flunga

+8  A: 

take a look at autoloading. this will reduce all your includes down to only what is required, when it is required.

nickf
Thanks so much. This is exactly what I need, and since the helpers originated from a PHP4 implementation this was something I was stuck with then, but not now. :) Thanks again
flungabunga
+1  A: 

Your best bet when constructing such dependencies to stay "acyclic". You can have higher-level functionality "require" the low level functionality it needs to operate, but design it in a way so that things do not point to each other.

This way, by breaking it into small enough units you will be able to ensure that when you don't need all the modules, only the minimal number of dependencies get pulled in.

I'm certainly unaware of any reason to "require" code you're not going to use in a page.

levik
Thanks levik. The application is so large that I find think it's gonna be more trouble to break apart and rebuild, the auto loading suggestion above is what I'll adopt, but I'll mark up your response as it is good advice which I always try to practice. Thanks.
flungabunga