Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Introduction of PHP object-oriented access modifier

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "PHP object-oriented access modifier introduction", the explanation content in the article is simple and clear, easy to learn and understand, please follow the small series of ideas slowly in-depth, together to study and learn "PHP object-oriented access modifier introduction" bar!

There are three access modifiers in PHP:

public (public, default)

protected (protected)

private (private)

They can be used on class properties and methods (collectively called class members), respectively, to modify access rights for class members.

public (public, default)

In PHP 5, if a class does not have an access modifier specifying a member, the default is public access.

/*

The following two methods declare access permissions with 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 (private)

Members defined as private are visible to all members within the class, with no access restrictions. Access is not allowed outside the class.

protected (protected)

Protected is a bit more complicated, being declared a protected member, allowing access only to subclasses of the class.

Access rights table:

access

public

protected

private

all

subclass

within-class

Thank you for reading, the above is the "PHP object-oriented access modifier introduction" content, after learning this article, I believe we have a deeper understanding of PHP object-oriented access modifier introduction this problem, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report