Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/71901-solved-how-many-classes/
Share on other sites

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????

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.

Thanks for the reply!  :D

 

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)?

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.