There are three access modifiers in PHP that are public by default

Source: Internet
Author: User
Tags modifiers

There are three types of access modifiers in PHP , namely:

Public (common, default)
Protected (Protected)
Private (privately)

They can be used, respectively, on the properties and methods of a class (the properties and methods of a class are collectively referred to as members of a class), and are used to decorate the access rights of class members.
Public (common, default)
In PHP5, if the class does not have an access modifier for the specified member, the default is public access.

/*
The following two methods declare access to the same effect
*/
function say () {};
PUBLILC function Say () {};

When a member of a class is declared as a public access modifier, that member can be accessed and manipulated by external code.
Private (privately)
A member that is defined as private and is visible to all members of the class without access restrictions. Access is not allowed outside the class.
Protected (Protected)
Protected is slightly more complex and is declared to be a member of the protected, allowing access only to subclasses of that class.

Access Status Table :

access

public

protected

private

All

Sub-class

In-Class

There are three access modifiers in PHP that are public by default

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.