Home >Backend Development >PHP Tutorial >PHP's three major object-oriented features: encapsulation

PHP's three major object-oriented features: encapsulation

WBOY
WBOYOriginal
2016-07-29 08:57:521014browse

Connect the members (properties, methods) of the object into an independent and identical unit, and hide the internal details of the object as much as possible

Here we will introduce the "private" keyword, private, use this keyword to modify Members can only be accessed inside the object and cannot be accessed outside the object

The role of encapsulated methods

1. After private encapsulation, it can only be used internally

2. There are 100 methods in a class , 90 are encapsulated (methods that serve the other 10), and only 10 methods can be used

The role of encapsulated attributes

1. Member attributes are equivalent to global variables of this object, and member attributes will be in methods When used in , changes in member attributes are changing the execution behavior of the method, that is, changing the function of the object

2. Do not allow the object to change or read its value

The above has introduced the encapsulation of the three major features of PHP object-oriented, including aspects of content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn