What are the differences between independent UDFs outside the class and static methods in the class?
function test(){………return $result;}function test1(){………return $result;}……function testN(){………return $result;}class funs{static function test(){………return $result;}static function test1(){………return $result;}……static function testN(){………return $result;}}$a = test();$b = funs::test()……
What is the difference between a separate function written outside the class and a static function written in the class? Is the function outside the class static? Is it also similar to the static method mentioned in the tutorial to save memory? Which of the following is more efficient?
Is it good to write common functions in a class and define them as static methods?
I am a newbie. please give me the correct advice!
Reply to discussion (solution)
According to php5.3 constraints, static methods can only access static attributes.
There is no big difference between static methods and common functions.
In fact, this strange writing method will gradually be replaced by namespaces.
Of course, some people may say that different classes can define static methods with the same name to achieve differentiation.
But the namespace is used for this purpose.
According to PHP? How does it work? Understanding:
Php every time? Row? When the function is written outside the class, it will be traversed first, but the function written in the class will not be traversed. However, I feel that static encapsulation is faster than external functions.
The OOP method is currently highly respected. Therefore, it is recommended to encapsulate the function into the class to become a static method. it will not be too cumbersome to use it.
At least all of my methods are encapsulated into the class and become static methods, such:
Class abc {
Public static function ff ($ ){
Echo $;
}
}
Abc: ff ('23 ');
Well, I feel like writing all the functions in the class as static will implement classification, and there is a rule like putting all the functions about files in the file class, etc, then the system _ autoload automatic call does not need to be manually included
However, I read a lot of well-known programs, but this is not the case. new users are confused.
You can try the differences between calling in the class and calling outside the class. I was far more impressed when I found and tested some questions by myself!
function test(){………return $result;}function test1(){………return $result;}……function testN(){………return $result;}class funs{static function test(){………return $result;}static function test1(){………return $result;}……static function testN(){………return $result;}}$a = test();$b = funs::test()……
What is the difference between a separate function written outside the class and a static function written in the class? Is the function outside the class static? Is it also similar to the static method mentioned in the tutorial to save memory? Which of the following is more efficient?
Is it good to write common functions in a class and define them as static methods?
I am a newbie. please give me the correct advice!
There is no difference in the transformation of a programming idea
My opinion is close to that of old Xu, and namespace is a trend.
Currently, some script parsing languages are slow to process namespaces, but I think they will be improved in the future.