In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
In this article, the editor introduces in detail "what are the access rights of class methods in php", with detailed content, clear steps and proper handling of details. I hope that this article "which kinds of access rights of class methods in php" can help you solve your doubts.
There are three kinds of access rights for class methods in php: 1, public types (public), which can be used inside the class, in subclasses, or outside the class without restrictions; 2, protected types (protected); and 3, private types (private), which can only be used inside the class, but cannot be used outside the class or in subclasses.
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
Member methods in a class
Functions defined in a class are called member methods. The only difference between a function and a member method is that the function implements an independent function, while the member method is a behavior in the implementation class and is part of the class.
You can declare multiple member methods in a class, and the declaration of a member method is exactly the same as that of a function, except that you can control access by adding some access modifiers before the function keyword, such as public, private, protected, and so on.
Access to the method
There are three types of access rights:
Public: a public type that can be used inside a class, in a subclass, or outside a class without restriction
Features: external callable, internal callable, subclass callable
In a subclass, you can call a public method or property through self::var, and parent::method calls a parent class method
You can call a method or property of type public through $obj- > var in the instance
Protected: protected type, which can be used inside and subclasses of the class, but not outside the class
Features: external can not be called, internal callable subclass can call
In a subclass, you can call a protected method or property through self::var, and parent::method calls a parent class method
You cannot call a method or property of type protected through $obj- > var in an instance
Private: private type, which can only be used inside the class, but not outside the class or in subclasses.
Features: external non-callable, internal callable, subclass non-callable
Properties or methods of this type can only be used in this class, and properties and methods of private types cannot be called in instances of this class, subclasses, or instances of subclasses.
Description:
When creating a method, if it is not specified, the default is public.
Results:
My age is: 33
Complement: the difference between self and parent
a)。 These two objects are commonly used in subclasses. The main difference between them is that self can call public or protected properties in the parent class, but parent cannot call
B) .self::, which represents static members (methods and properties) of the current class, unlike $this, which refers to the current object
After reading this, the article "what are the access permissions of class methods in php" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself to understand it. If you want to know more about related articles, welcome to follow the industry information channel.
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.