Previously we talked about classes and objects and instantiated classes. for example, we created a person's class. However, people are not just attributes, but also behavior patterns, such as running, dancing, singing, and eating. So how can we implement these behaviors? Next, we will use our member method to implement it. The example of the previous lesson defines a person's class,
Member method
Previously, we talked about the definition and instantiation of php classes. for example, we created a person's class.
However, people are not just attributes, but also behavior patterns, such as running, dancing, singing, and eating. So how can we implement these behaviors? Next, we will use our member method to implement it.
The example of the previous lesson defines a person's class and creates a running Member method.
Class Preson {public $ name; public $ age; public $ gender; public function Run () {// declare the member method echo "";}} // instantiate a class $ Preson1 = new Preson (); $ Preson1-> name = "demassiya"; // call the member method $ Preson1-> Run ();
This example is a simple call to create a member method.
Member variables
The variables in the class, also known as member variables, have been used in our previous examples. here we will introduce them to you.
Class Preson {public $ name; // defines the member variable public $ age ;}
In the above example, $ name is a member variable.
Class constant
If there are variables in the class, there will be constants. A constant is a constant value that does not change.
Define constants. We use const.
Name = "Aesop"; echo 'I want to play'. $ character1-> name .'
'.' Skill is '. character: SKILLS;
The above example illustrates the definition and access methods of constants.
The above is php object-oriented: detailed content of member methods, member variables, and class constants. For more information, see other related articles in the first PHP community!