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 a class and a static function written inside a class? Is the function outside the class static? Also like in the tutorial, the static method of saving memory? If they want to compare efficiency, which is high?
Is it good to write a commonly used function in a class as a static method?
I am a novice, please hand to give the correct advice!
Reply to discussion (solution)
Static methods can only access static properties, as constrained by php5.3
Well, there's no big difference between a static method and a normal function.
In fact, this singular writing will gradually be replaced by the namespace
Of course, some people would say that different classes can define static methods with the same name to achieve differentiation
But namespaces are used for this purpose.
In accordance with the principles of the PHP line? Understanding:
PHP every time you write a function outside of a class he will go through it, and the one written in class does not traverse, but from then on I feel that the static package speed will be faster than the external function.
The OOP approach is currently respected, so it is recommended to encapsulate function into class as a static method. It's not too tedious to use.
At least mine. The method is all encapsulated in class as a static method, such as:
Class abc{
public static function ff ($a) {
echo $a;
}
}
ABC::FF (' 23 ');
Well, the feeling of putting functions in a class is a static implementation of the collation, there is a sense of the rules, such as the function of the file is placed in the files class and so on, and then used when the system __autoload automatic calls do not have to manually include
But see a lot of more well-known procedures, not to do so, novice very confused hehe
The difference between the two can be called in the class and the class outside the call to try to understand. Some questions to discover and test yourself far more impressive than to ask!
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 a class and a static function written inside a class? Is the function outside the class static? Also like in the tutorial, the static method of saving memory? If they want to compare efficiency, which is high?
Is it good to write a commonly used function in a class as a static method?
I am a novice, please hand to give the correct advice!
A change in the idea of programming, without any distinction
My opinion and the old Xu approach, the namespace is trending
It's just that some script parsing languages are slow to handle namespaces (just relative), but I think it will improve later.