In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "what is the difference between inheriting classes and implementing interfaces in php". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
The difference between inheritance class and implementation interface in php: 1, PHP inheritance belongs to single inheritance, which ensures oneness, but it is not flexible enough, and the implementation interface is a supplement to single inheritance; 2, the implementation interface can extend the function of a class without destroying the hierarchical relationship.
Operating environment of this tutorial: windows10 system, PHP7.1 version, DELL G3 computer
The difference between inheriting classes and implementing interfaces in php
1. Comparison of inheritance and implementation interfaces:
(1) php inheritance belongs to single inheritance, which ensures oneness, but it is not flexible enough. Implementing an interface is a supplement to a single inheritance
(2) the implementation interface can extend the function of a class without destroying the class hierarchy.
2. Final keyword:
1. If a class does not want to be inherited by other classes (from a security point of view), you can modify it with final
2. If you want a method not to be overwritten by a subclass (you don't want the method to be overloaded by a subclass method), you can also modify it with final.
3. Final cannot modify member variables (attributes).
3. Const:
1. When an attribute does not want to be modified, you can consider using const as a constant, such as pi, which cannot be tampered with.
2. Basic grammar:
Const constant name = assign initial value
If the initial value is not assigned, it cannot be tampered with later.
3. Constants cannot write modifiers, default public but cannot be written out.
4. Constant names are generally all named in uppercase letters.
5. Call syntax:
Use inside the class:
The name or class name of the self:: constant:: constant name
Use outside of the class:
API name:: constant
This is the end of the content of "what is the difference between inheriting classes and implementing interfaces in php". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.