I have a class with a few rather large methods. In it's basic and most common state most of the functionality is not required though, so I was wondering if there is a way of lazy loading just parts of the class. The methods need to be able to access private/protected members so it would be ideal if the methods were native to the class, however in looking for other solutions I came across this which discusses using private members in callbacks which would be a workable solution (I'd use separate classes that contain a function that calls the callback and lazy load that class). That was 2009 though and whether this functionality has been removed in later versions of PHP i don't know, but it doesn't seem to be working here with 5.3.5
Is there a way of doing this, or do you have any suggestions for other patterns I should be looking at?
Thanks.
Wow! Thanks for all the answers. I think the point a number of you make regarding this being a probable premature optimization, or worse, not an optimization at all is very valid and I will be doing profiling to check that any solution I settle on is actually helping not hurting. ... Now to read and digest all your thoughts properly. Thanks again.