I'm starting to work with object orientation in PHP and would like to know if the number of classes in a system can interfere with its performance, or if there were to be hundreds of classes in order to really performance could begin to be affected.
I'm starting to work with object orientation in PHP and would like to know if the number of classes in a system can interfere with its performance, or if there were to be hundreds of classes in order to really performance could begin to be affected.
Speaking more of the same, it makes no difference. The explanation is in the other answers.
One practical point to keep in mind is how these classes are loaded.
You'll probably want to use an autoloader. Then yes, in this case will consume processes that greatly influence performance.
An autloader is to include a file when it invokes a class that is not present in the body of the script. This process of including the file consumes a lot of memory and processing.
To reduce this cost, we recommend creating build caches. Also we can opt or reinforce with cache libraries like Memcache, APC, Opcode, among others.
However, if the concern is whether the use of OOP classes or concepts will render the system less performative than procedural style code writing, obviously the procedural style is much faster. However, think this way, you need to go from your house to the corner bar which is 20 meters away. How are you going?1. a pé
2. de moto
3. de lamborguini
I will believe that you have opted for option 1.
Now, suppose you want to go from your house to Paris.
1. a pé e segue nadando pelo oceano
2. de moto e segue de barco a remo pelo oceano
3. vai até um aeroporto e segue de avião
I think you've opted for the plane.
But why does a plane consume much more resources and is it heavy? Can not you walk and swim in the ocean? After all, it gives the same result.
Think of this analogy or similar analogies and you will understand when to use a style or concept.
Always think of the ultimate goal. What cost / benefit will the X or Y option generate?
Consider cost-effectiveness, think about effectiveness.
Is the cost / benefit effective?
These are basic steps to make a more appropriate choice.
The number of classes makes no noticeable difference. What you do in them can make a difference.
Of course the difference is, but that's not why you should use classes or not.
The term "calling classes" does not even make sense.
Classes are used to organize the code, so use the ones to organize. Or stop using if this organization has no advantage whatsoever. And in PHP it is common for it to not bring advantage. There is excessive use of classes in most codes. Usually a person uses a class because they do not know what they are doing, it just follows the flow.
There is no problem creating classes when they will bring something useful, if the person can clearly and individually justify their need. If it can not do this - and it is not enough to give a generic justification of the type "will organize the code" - it is because the class is not necessary.
So the concern should not be this. And if it is, probably should change language, since PHP is not a language to be fast, is to develop fast. This shows how strange it is to use classes in the language, since it refers to OOP which is a more well-engineered development and would be useful in complex systems, not in scripts systems.
The right depends on the context. Anyone who says things like this that is right to one side or the other in general terms is just parroting. You have to analyze the problem to decide what to do. Experience counts in these cases. When you do not have it, you have to ask for help, but you have to ask in terms that you can give an analysis, this is not easy, and especially not usually fit here, unless the person knows how to ask.
It is common for a person to choose a form without plausible justification. She picks a shape and goes in without thinking.
Some questions that may help you better understand the subject:
Performance will depend on how classes are used, how they are written, how they behave and how they relate, and the characteristics of the server hosting your application. Simply having the class in the system does not affect performance.