member Methods
Before we talked about the definition and instantiation of the PHP class, for example, we created a class for a person.
But people not only have attributes, but also behavior, such as people can run, can Dance, can sing, can eat and so on. So, how do we go about implementing these behaviors? The next step is to use our member approach to achieve it.
Or an example of the last lesson, defining a person's class, creating a running member method
Class preson{public $name; public $age; public $gender; Public Function Run () { //Declare member Method echo "Man in Tower"; }} First instantiate a class $preson1 = new Preson (), $Preson 1->name = "Demacia";//Call member Method $preson1->run ();
This example is a simple member method of creating a call.
Member variables
A variable in a class, also called a member variable, has been used in our previous example and is presented here to illustrate.
Class preson{public $name; Define member variables public $age;}
The $name in the example above is the member variable.
Class constants
There are variables in the class, then there will be constants relative to them. Constant means that the quantity that does not change is a constant value.
Define constants, we use Const.
<?phpclass character{public $name; Declare a variable const SKILLS = ' grams '; //Declare a constant} $character 1 = new character (); $character 1->name = "ya"; Echo ' I'm going to play '. $character 1->name. ' <br/> '. ' Skill is '. Character::skills;
The above example shows how constants are defined and how they are accessed.