I am a little confused. under what conditions should I use static in the class? & lt ;? Php & nbsp; class & nbsp; cls {& nbsp; & nbsp; & nbsp it's a bit confusing when static is used in the class.
class cls{
public static function print_str(){
echo 'OK';
}
}
cls::print_str();
?>
The static method is a static method, which can be directly used without an instance class.
Under what circumstances should static be used to define class methods? is it based on convenient calls?
If there is only one method in the class, it is defined as static or non-static; there is no difference in efficiency.
It should be a relatively simple question, but I have to ask a question if I have a good foundation. Thank you. Class static
------ Solution --------------------
The static method is a function with limited scope, that is, the host name must be used.
I don't see any advantages if I use it only as a function.
If it is used for Object connection in Singleton mode, it is more convenient.
Object transfer is not required
------ Solution --------------------
Reference:
The static method is a function with limited scope, that is, the host name must be used.
I don't see any advantages if I use it only as a function.
If it is used for Object connection in Singleton mode, it is more convenient.
Object transfer is not required
Compared with non-static methods, it does not need to instantiate the entire class. It consumes less performance. Compared with global functions, it can use class features. Inheritance, encapsulation, and other features.