In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 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 "how to use the function of the construction method 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 function of the construction method "_ _ construct ()" in php is to initialize the object when creating the object, that is, to assign the initial value to the object member variables, which is always used together with the new operator in the statement to create the object; the syntax "public function _ construct (parameter list) {...}".
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
PHP _ _ construct (): constructor / method
A constructor / method (constructor method, also known as a constructor) is a special method in a class that is automatically called when an object is instantiated with the new keyword.
The usage in PHP3.0 and PHP4.0 is discarded in PHP7.0, and the constructor must be defined using _ _ construct.
A constructor is the first function that is automatically called in a class when an object is created, and only one constructor can exist in a class. Similar to ordinary functions, constructors can also take parameters, and if the constructor has parameters, then the corresponding parameters need to be passed in the instantiation, such as new Students ($name, $age).
The purpose of the php constructor is to initialize the object when it is created, that is, to assign an initial value to the object member variable, which is always used with the new operator in the statement that creates the object. A particular class can have multiple constructors, which can be distinguished according to the number of parameters or the type of parameters.
Syntax:
Public function _ _ construct (parameter list) {...}
Where the parameter list is optional and can be omitted when it is not needed.
If the constructor is not explicitly declared in the code, there is a constructor with no argument list and empty content in the class by default. If the constructor is explicitly declared, the default constructor in the class will not exist. So constructors are usually used to do some preparatory work, such as assigning values to certain parameters.
Note: if the constructor is explicitly declared, its access must be public, and the constructor is called automatically when instantiated, and we do not need to call it manually.
[example] create a class and create a constructor for its display, as follows:
This is the end of the content of "how to use the function of constructors in php". Thank you for your 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