php - $classInstance->title is faster than $classInstance->getTitle() - so why do most people use the slower method? -
I have recently been reading articles about optimizing the code for scalability in PHP.
So basically, they say:
If you have a class like this:
class myClass {public $ something; Public Function Set Some ($ val) {$ this- & gt; Something = $ val; } // function end} // class end $ myClassInstance = new myClass; and you want to get the class property
$ something , you should do this:
// echo $ something MyClass $ myClassInchance-> Something;
And not this:
// Use an additional method (getSomething ()) to reshuffle something from myClass that returns the property $ myClassInstance -> gt; take some ();
Because speed variation is frustrated, the method is slow (
$ myClassInstance-> getSomething () ) That is why it has been disappointed.
But, I still disappointed many people (tutorials, code examples, ect).
So my question is, is there any benefit or something that is established on private property for any reason, if I was Is that missing me to use the discouraged method? If so, what?
What if you want to apply some arguments in your "GetTitle" later on to start the special argument Can filter or change some output? You do not know when these things will start. Additionnaly, people say that the function accelerator is slow, it is using 1 million loops for the benchmark, but seriously, you are going to display 1 million titles a page?
Comments
Post a Comment