PHP object-oriented programming _ PHP Tutorial

Source: Internet
Author: User
PHP object-oriented programming learning. One of PHP object-oriented programming learning inheritance 1. class members defined in the parent class do not need to be repeatedly defined in the subclass, saves programming time and cost. 2. the subclass of the same parent class has one of the PHP object-oriented programming learning classes.
Inheritance
1. the class members defined in the parent class do not need to be repeatedly defined in the subclass, saving programming time and cost.
2. the child classes of the same parent class have class members defined by the same parent class. Therefore, external code can call them equally.

3. subclass can modify and adjust the class members defined by the parent class.

 Weight;} public function setWeight ($ w) {$ this-> weight = $ w ;}} class Dog extends Animal {/*** New subclass method */public function Bark () {echo "Wang ~~ Wang ~~~ ";}}$ MyDog = new Dog (); $ myDog-> setWeight (20); echo" Mydog's weight is ". $ myDog-> getWeight ().'
'; $ MyDog-> Bark ();?>


Access control
1. object-oriented permissions
(1) public: shared class members, which can be accessed at any place
(2) protected: protected class members can be accessed by themselves and their subclasses.
(3) private: private class members can only be accessed by themselves.

Static keywords)
1. static attributes are used to save the common data of the class.
2. only static attributes can be accessed in static methods.
3. static members can be accessed without instantiating objects
4. the class can access its static members through self or static keywords.
5. use the parent keyword to access static members of the parent class.
6. you can use the class name to define external access to static members in the class.


Final member
1. for classes that do not want to be inherited by any class, you can add the final keyword before the class.
2. for methods that do not want to overwrite the quilt class, you can add the final keyword before the method definition.


Data Access
1. the parent keyword can be used to access the method of quilt class rewriting in the parent class.
2. the self keyword can be used to access its own static members and class constants, or to access its own attributes; when using constants, you do not need to add the '$' symbol before the constant name.
3. the static keyword is used for static members defined by the category class. to access static attributes, you must add the '$' symbol before the attribute.

Category inheritance 1. the class members defined in the parent class do not need to be repeatedly defined in the subclass, saving programming time and cost. 2. the subclass of the same parent class has phase...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.