PHP is the scripting language for weak variables, which means you do not need to define them first. It can also give a lot of freedom, but for programs, freedom is not a good thing. It brings a lot of trouble to protect staff browsing in the future. The following PHP is a scripting language with weak variables. that is to say, you do not need to define them first, which is very flexible. It can also give a lot of freedom, but for programs, freedom is not a good thing.
It brings a lot of trouble to protect staff browsing in the future.
Next we will enter our first program:
1. php
////////////////////
<? Class helloWorld {
Var $ hellow_str = 'Hello World! ';
Function helloWorld (){
Echo $ this-> hellow_str;
}
}
$ P = new helloWorld;
?>
//////////////////// |
Obviously, this is a class, a simple class, with only one structure function. The goal is to output 'Hello world'. First, we define a class member variable and output this variable through a special $ this object. I am not very refined in the oop idea, it is only used in php Development. Others are only used for authentication, but I think it is sufficient for php developers.
Next, describe what is the $ this object. From this point, we must first know what is a class.
Class, can be described as a group of similar groups, member variables in the class, the above $ hellow_str can be seen as a strange feature of this group, for example, the table group is
Class, the table has the desktop, the table foot, these "all have" things, is all the common characteristics of the table, in the program class we can define it as a member variable of the table class.
////////////
Class desktop {
Var $ desktop; # table surface;
Var $ baluster; # table legs;
}
/////////// |
Similarly, in the world of tables, they also share common actions, such as moving [maybe you are pushing the table now ^], or we may want to enlarge the face of the table, in the same way, this is a common method proposed by the table group. [it is similar to the features, but it is just an action.] Let's add this common feature to the class.
////////////////
Class desktop {
Var $ desktop; # table surface;
Var $ baluster; # table legs;
Function move (){
#....
}
Function largen (){
#...
}
}/////////////// |
Now that you know the above, you can understand what the $ this object is. no error occurs. it is a specific object in the table group. if you still cannot understand it,
Next we will explain.
For example, if we want to increase the area of a table, we will not target a group of tables, but the specific table to be rectified. this is an individual! Therefore, we need to "instantiate" this class for refined location. We don't need to make any changes to other tables.
////////////////
Class desktop {
Var $ desktop; # table surface;
Var $ baluster; # table legs;
Function move (){
#....
}
Function largen (){
$ This-> desktop; # enlarge the table surface
}
}
$ D = new desktop; # "instantiate. at this time, we pull a specific table!
$ D-> largen (); # Haha, zoom in on a specific table. $ D = $ this; do you understand that $ d is the specific table, $ d-> largen is used to zoom in on a specific table [all the others in the table group.
/////////////// |
Originally, $ this refers to a specific table. haha, I understand that the class is a collection of all attributes and methods, and a specific object, it is an individual in this group. since it is an individual in this group, it certainly has the common characteristics of the group and Fang Fara.
[1] [2] Next page