Simple difference between public&private&protect in PHP and usage introduction

Source: Internet
Author: User
Tags php class
This article brings the content is about PHP in the simple difference between public&private&protect and usage introduction, there is a certain reference value, the need for friends can refer to, I hope to help you.

Public "common"

Can be called from anywhere in the program (within the class, outside the Class) by other classes and objects. Subclasses can inherit and use all public members in the parent class.

Private "privately-owned"

Variables and methods that are modified by private can only be called and modified within the class in which they are located, and cannot be accessed outside of the class. It is also not possible in subclasses.

If called directly, an error occurs.

Protect "protected"

Class members decorated with protected can be called in this class and in subclasses, but cannot be called anywhere else.

Related recommendations:

PHP5 in public,private,protected

public,private,protected Differences in PHP class, and examples

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.