Encapsulation of php Object-Oriented Programming-PHP development

Source: Internet
Author: User
Encapsulation is the three major features of object-oriented programming. encapsulation is to combine the member attributes and member methods of an object into an independent and identical unit, and try to hide the internal details of the object, form a boundary, and retain only a limited number of external interfaces to associate them with the external. The encapsulation of member attributes or member methods is achieved by adding the keyword private before it. Class Members modified by private cannot be accessed externally, but members inside the object can access the encapsulated members inside the object, the encapsulation of object members is one of the three main features of object-oriented programming. encapsulation is to combine the member attributes and member methods of an object into an independent and identical unit, it tries its best to conceal the internal details of the object, form a boundary, and retain only a limited number of external interfaces to associate them with the external.


Encapsulation Implementation Method

The encapsulation of member attributes or member methods is achieved by adding the keyword private before it. Class Members modified by private cannot be accessed externally, but members inside the object can access the encapsulated members inside the object to protect the members of the object.

We use private to encapsulate members in the Person class:

 

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.