What are the differences between independent UDFs outside the class and static methods in the class? Function & nbsp; test (){......... Return & nbsp; $ result;} function & nbsp; test1 (){......... Return & nbsp; $ result ;}...... What are the differences between independent UDFs outside the functio 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! Share:
------ 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.
------ Solution --------------------
According to the principle of PHP commit:
Php will traverse the function written outside the class every time it completes the row, 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.
------ Solution --------------------
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 ');
------ Solution --------------------
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!
------ Solution --------------------
Reference:
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(){