Introduction to PHP object-oriented access modifiers

Source: Internet
Author: User
Tags modifiers
They can be used in the class attributes and methods (class attributes and methods are collectively called class members) to modify the access permissions of class members. PHP has three access modifiers:

Public (public, default)
Protected (protected)
Private)

They can be used in the class attributes and methods (class attributes and methods are collectively called class members) to modify the access permissions of class members.
Public (public, default)
In PHP5, if the class does not specify the access modifier of the member, the default access permission is public.

/*
The following two methods declare that the access permission works the same
*/
Function say (){};
Publilc function say (){};

When a class member is declared as a public access modifier, the member can be accessed and operated by external code.
Private)
A private member is visible to all members in the class and has no access restrictions. Access to the outside of the class is not allowed.
Protected (protected)
Protected is a little complicated. it is declared as a member of protected and can only be accessed by subclass of this class.

Access permission list:

Access permission

Public

Protected

Private

All

Subclass

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.