In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "what is the difference between public and private in php". In the actual case operation process, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!
If a class member is declared public, it can be accessed anywhere; if a class member is declared private, it can only be accessed by the class that defines it. 2, public is a public type, permissions are the largest, can be called internally, instance calls, etc.;private is a private type, only used in this class.
Operating environment of this tutorial: Windows 7 system, PHP7.1 version, DELL G3 computer
Public, private and protected are called access modifiers. Just like C++, PHP has three access modifiers, public, private, and protected. You can define the visibility of attributes, methods, or constants by prepending declarations with these keywords.
If a class member is declared public, it can be accessed anywhere.
Public permissions are the largest, can be called internally, instance calls, etc.
If a class member is declared protected, it can only be accessed within the class itself and within inheritance and parent classes.
protected is a protected type for calls to this class and inherited classes.
If a class member is declared private, it can only be accessed by the class that defines it.
Private is a private type and is used only in this class.
Examples:
From the example above, we can see that:
public: can be called internally to class, can be instantiated.
private: can be called within class, instantiation calls error.
protected: can be called within class, instantiation call error.
From the example above, we can see that:
public: public in test can be inherited.
private: private in test cannot be inherited.
protected: protected in test can be inherited.
static: static in test can be inherited.
"What is the difference between public and private in PHP" is introduced here. Thank you for reading it. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.