phpFirstJoy Posted October 5, 2007 Share Posted October 5, 2007 Hi again, I have another question that I would like to ask. This time it's about classes. Now, I know how great OOP is and all but I tend to have a class for statistical logging, user functions, authenticating users, error logging, page templating, database methods, page caching, and I'm sure I can come up with a much longer list. The problem I'm encountering is that I need almost all these classes on nearly every page. So when a page is called up, it loads most of the classes and whatever else I've included before running them and finally displaying the page. This makes loading time really slow. How would I improve page loading? Are there some classes that I should get rid of? Maybe I'm not designing my classes correctly? All of the above? I'd appreciate the help. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/71901-solved-how-many-classes/ Share on other sites More sharing options...
sc Posted October 5, 2007 Share Posted October 5, 2007 I would also like to know peoples views on this. I am currently using zend framework to create a web application, but from where im stood, the framework MASSIVELY bloats the code by having classes for every damn thing! I cant help feeling that i could get most tasks done, in just as much time as it takes to use the framework, with a lot less code footprint..... thoughts anyone???? Quote Link to comment https://forums.phpfreaks.com/topic/71901-solved-how-many-classes/#findComment-362281 Share on other sites More sharing options...
phpFirstJoy Posted October 8, 2007 Author Share Posted October 8, 2007 74 views by so many including experts but no suggestions? Kinda depressing... :-\ Quote Link to comment https://forums.phpfreaks.com/topic/71901-solved-how-many-classes/#findComment-364248 Share on other sites More sharing options...
TomKrush Posted October 8, 2007 Share Posted October 8, 2007 What are the filesizes for these classes. Loading a class shouldn't take anytime at all. If the filesizes are large then it will slow down the program. The reason for another possible slow down is accessing the filesystem too many times. If you are programming in PHP 5 you can use what is called __autoload which can be found at http://docs.php.net/autoload. Quote Link to comment https://forums.phpfreaks.com/topic/71901-solved-how-many-classes/#findComment-364324 Share on other sites More sharing options...
phpFirstJoy Posted October 9, 2007 Author Share Posted October 9, 2007 Thanks for the reply! Hmmm well, they are small files but there are a lot of parent and child classes all linked together. Then most of the functions/methods need to connect to the database. Maybe I'm opening too many connections... would it work if I do something like this... <?php //include_once class 1 //include_once class 2 //.... //create the class object 1 //create the class object 2 // etc... //open database ... ?> I'm just concerned that because I create my class objects before the database connection is opened, that they won't be able to do anything. Should I create the objects after I create a link to the database? Would this be a better solution than opening the database within the parent/child classes themselves (I only do it when it's needed in the function then I close it right away)? Quote Link to comment https://forums.phpfreaks.com/topic/71901-solved-how-many-classes/#findComment-365233 Share on other sites More sharing options...
TomKrush Posted October 9, 2007 Share Posted October 9, 2007 You can load in the class and start the object before the database connects as long as your __construct doesn't need the database. I tend to import all my classes connect to the database and finally execute the rest of the code. Quote Link to comment https://forums.phpfreaks.com/topic/71901-solved-how-many-classes/#findComment-365722 Share on other sites More sharing options...
Jenk Posted October 9, 2007 Share Posted October 9, 2007 this is essentially th crux of application design. "Do you really, really need every object on overy request?" is thet question you are asking, alongside every other developer asking the same question about his or her application. Implement autoload to leviate the worry of "should I include?" for starters, then move on to actual design practice and examine your application logic. Are you instantiating objects "just in case" ? Do you really need multiple instances of ClassA object? etc. Often there are 100's of objects, dozens of classes, in use at anytime in applications. Quote Link to comment https://forums.phpfreaks.com/topic/71901-solved-how-many-classes/#findComment-365757 Share on other sites More sharing options...
phpFirstJoy Posted October 13, 2007 Author Share Posted October 13, 2007 Hi everyone, thanks for all the suggestions! I will definitely try them out. (this is so difficult!) but hopefully, I'll get used to it and I won't load too much stuff in the future. Quote Link to comment https://forums.phpfreaks.com/topic/71901-solved-how-many-classes/#findComment-368340 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.