In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of "whether there is a facade class in thinkphp3". The editor shows you the operation process through an actual case. The operation method is simple and fast, and it is practical. I hope that this "thinkphp3 has a facade class" article can help you solve the problem.
Thinkphp3 has a facade class. Facade provides a static calling interface for classes in the container, which has better testability and extensibility. You can define a facade class for any non-static class library with the syntax of "class Test {public function Class () {return path;}}".
This article operating environment: Windows10 system, ThinkPHP3 version, Dell G3 computer.
Does thinkphp3 have a facade class?
Facade provides a static calling interface for classes in the container, which brings better testability and extensibility than traditional static method calls. You can define a facade class for any non-static class library.
Why do you use facade?
1. The difference between static methods and non-static methods (calling objects and reference variables are different)
Static methods: methods that are modified with the static keyword, also known as class methods. If it belongs to a class, it does not belong to an object, and you can use the class name before instantiating the object. The method name calls a static method. Static properties and static methods belong to the class and can be called directly through the class name.
a. In static methods, static methods can be called.
b. In static methods, non-static methods cannot be called.
c. In static methods, you can reference class variables (that is, variables decorated by static).
d. In static methods, member variables cannot be referenced (that is, variables that are not decorated by static).
e. The super and this keywords cannot be used in static methods
Non-static method: a common method without the modification of the static keyword, also known as instance method, member method. Belonging to or not belonging to a class. (member properties, member methods belong to an object, which must be created through the new keyword and then called through the object).
a. In a normal method, you can call a normal method.
b. In normal methods, static methods can be called
c. In normal methods, class variables and member variables can be referenced
d. In normal methods, you can use the super and this keywords
2. The difference between static methods and non-static methods (calling methods are different)
Static methods can be called directly, class name calls and object calls. (class name. Method name / object name. Method name)
However, non-static methods can only be called through objects. (object name. Method name)
3. The difference between static and non-static methods (life cycle is different)
The life cycle of a static method is as long as the corresponding class, and static methods and static variables are allocated and loaded into memory as the class is defined. Static properties and methods are not destroyed until the thread ends. (that is, static methods belong to the class)
The life cycle of a non-static method is as long as the instantiated object of a class. A non-static method is created only when the class instantiates an object, and when the object is destroyed, the non-static method is destroyed immediately. (that is, non-static methods belong to objects)
Summary:
The class method can be called directly through the class name. The instance method must first instantiate the class, then initialize the object, and then call through the instance object of the class.
How to use
1. Create a folder facade where the facade class needs to be placed
2. Write your own public class
3. The code for creating a facade class in facade is as follows
Use think/Facade;class TestFacade extends Facade {protected static function getFacadeClass () {return 'written absolute path of target public class';}}
4. When calling this public class, you can directly use the facade class to replace the public class, so that the non-static methods of the public class can also be called statically.
This is the end of the introduction to "whether there is a facade class in thinkphp3". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
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.