Ec (2); Exploring classes ~~ It took me half a year to understand the role and Implementation of the class. There is not an article that can help me understand (I have never touched any OO stuff before ). In my opinion, the Class used in PHP is an informal language and cannot be determined whether it is correct. It is easy to create a class: What is the classmy_class {} class doing? Many people refer to it as a black box. Here I call it an independent whole. We only know the class name, but do not know script ec (2); script
Exploration of classes ~~ It took me half a year to understand the role and Implementation of the class. There is not an article that can help me understand (I have never touched any OO stuff before ).
In my opinion, the Class used in PHP is an informal language and cannot be determined whether it is correct.
Creating a class is simple:
Class my_class {}
What is the class? Many people refer to it as a black box. Here I call it an independent whole. We only know the class name, but do not know what is in it. So how should we use this class?
First, you need to know whether the public variable is defined in it-technically, it is called "attribute ".
Second, you need to know what function is defined in it-in professional terms, it is called "method ".
I am confused by these technical terms, So I simply ignore it.
How does one define public variables in a class?
It's easy. let's expand the my_class class:
Class my_class
{
Var $ username;
}
The above is simple. We have defined a public variable, which is composed of common variables with var spaces. What is its use? In the function, if we want to access variables outside the function, do we need to make a global operation first? The same is true for this purpose. It allows all functions in this class to access it, and it is different from a function, is the external class can also access and control this variable at any time, I will talk about how to access it externally. Another difference is that you cannot assign values to this variable using complex statements (you can read the rules yourself after understanding the class ).
Give it a default value:
Class my_class
{
Var $ username = "Deep Space ";
}
OK, defines a public variable, and then defines a function (that is, the so-called "method "):
Class my_class
{
Var $ username = "Deep Space ";
Function show_username ()
{
}
}
This definition function is no different from the normal definition function form. It's easy to define a function that prints $ username:
Class my_class
{
Var $ username = "Deep Space ";
Function show_username ($ username)
{
Echo $ username;
}
}
Some people may be confused here. There are now three $ usernames. Which is it ~~