tags:

views:

193

answers:

2

Is there any gain to combining all of the classes for a project into one massive 'compressed' file (spaces and comments removed) vs loading each class as they are required (other than all of the classes are there so you don't have to require/include them, isn't that what we have __autoload for?)?

It seems to me that loading each class as needed would be a lot less strenuous on php.

+1  A: 

Generally, in the vast majority of cases, for any non-trivial number of classes, you want some kind of dependency injection. The overhead of the dependency injection (via whatever method) will be dwarfed by the resources needed to parse a bunch of classes that won't get used in a particular request.

A lot has been written on the subject of how to efficiently manage loading classes as needed.

timdev
That is what I thought... it seems a silly practice to load everything and then not use half of it
SeanJA
+1  A: 

If you use a bytecode cache like APC, there's likely no performance gain to be had from "minifying" your PHP (removing whitespace and comments). The only benefit would be obfuscation -- which isn't going to buy you much anyway.

And yes -- loading 30 classes when you only need 1 is going to be a waste of resources.

Frank Farmer