One of PHP object-oriented Programming learning
Inherited
1. Class members defined within the parent class can save programming time and cost by not repeating definitions in subclasses
2. Subclasses of the same parent class have the same class members as defined by the parent class, so they can be treated equally when external code calls them.
3. Subclasses can modify and adjust class members defined by the parent class
Weight;} Public Function Setweight ($w) {$this->weight = $w;}} Class Dog extends animal{/*** subclass New method */public function Bark () {echo "wang~~wang~~~";}} $myDog = new Dog (), $myDog->setweight, echo "Mydog weight is". $myDog->getweight (). '
'; $myDog->bark ();? >
Access control
1, object-oriented three kinds of permissions
(1) Public: A common class member, can be visited in the classroom place
(2) Protected: A protected class member that can be accessed by itself and its subclasses
(3) Private: A privately-owned class member that can only be accessed by itself.
static keywords (statics)
1. Static properties are used to hold common data for a class
2. Static methods can only access static properties
3, static members do not need to instantiate the object can be accessed
4. The inside of a class can access its own static members through self or static keywords
5. You can access static members of the parent class by using the parent keyword
6. You can access static members outside the class definition through the name of the class
Final member
1. For classes that do not want to be inherited by any class, you can add the final keyword before class
2. For methods that do not want the quilt class to be overridden, you can add the final keyword before the method definition
Data access
1. The parent keyword can be used to access the method of overriding the quilt class in the parent class
2. The Self keyword can access the member methods of the class itself, or it can be used to access its own static members and class constants, cannot be used to access properties of the class itself, and constants are not required to add the ' $ ' symbol before the constant name
3. The static keyword is used to access statically defined members of the class, and it is necessary to add a ' $ ' symbol before the property to access the static property.
http://www.bkjia.com/PHPjc/953322.html www.bkjia.com true http://www.bkjia.com/PHPjc/953322.html techarticle PHP One of the object-oriented programming learning inheritance 1, the parent class within the definition of the class members can not be repeated in the subclass definition, saving the programming time and cost 2, the same parent class of the child class has a phase ...