In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, the editor will share with you the relevant knowledge about the role of the construction methods in php. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article.
In PHP, the function of the constructor is to initialize the object when creating the object, that is, the object member variables are assigned initial values; the constructor is used together with the new operator in the statement to create the object, and a special class can have multiple constructors, which can be distinguished according to the number or type of parameters.
This article operating environment: Windows10 system, PHP7.1 version, Dell G3 computer.
What is the function of the constructor in php
PHP allows developers to define a method in a class as a constructor. Classes with constructors call this method every time a new object is created, so it is ideal for doing some initialization work before using the object.
If a constructor is defined in a subclass, the constructor of its parent class is not implicitly called. To execute the constructor of the parent class, you need to call parent::__construct () in the constructor of the subclass. If the subclass does not have a constructor defined, it inherits from the parent class like a normal class method (if it is not defined as private).
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.
The constructor in PHP is defined using _ _ construct ()
Class demo {var $a; var $bbot function outAB () {echo $this- > a; echo $this- > b;}}
There are no refactoring variables $an and $b in the demo class. Refactoring variables can be written this way.
$cs = new demo (3jue 5); / / define $an as 3 meme b as 5.
Use _ _ construct () directly in the class:
Class demo {var $a; var $b; function _ construct ($a dagger b) {$this- > astata; $this- > bouncy;} function outAB () {echo $this- > a; echo $this- > b;} $cs = new demo (3jue 5); $cs- > outAB (). These are all the contents of the article "what are the functions of the construction methods in php?" Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to 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.