Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use the php constructor _ _ construct ()

Shulou Source: shulou.com Published: 2022-05-31 10:55:05 10月24日 Update

In this article Xiaobian for you to introduce in detail the "php construction method _ _ construct () how to use", the content is detailed, the steps are clear, the details are handled properly, I hope this "php construction method _ _ construct () how to use" article can help you solve your doubts, following the editor's ideas slowly in-depth, together to learn new knowledge.

Concept

1. The construction method _ _ construct () is a special method with unique structure.

2. The method is specified by the system, the developer only needs to write once when defining it, and the object is called automatically after the class with constructor instantiates the object.

Syntax:

Function _ construct (arg1,arg2,...) {.}

Attention to use

If both the parent class and the subclass have _ _ construct, only the _ _ construct of the subclass will be called, and the _ _ construct of the parent class will not be called automatically

The _ _ construct method of a subclass if you want to call the _ _ construct method of the parent class, you must call the constructor of the parent class in the constructor of the subclass

Example

Class People {public $name; private $sex; protected $height; public function _ _ construct ($name) {echo $name. "say:". "Knowledge is power!";}} $man = new People ("Zhang San") After reading this, the article "how to use php construction method _ _ construct ()" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it yourself. If you want to know more about related articles, welcome to follow the industry information channel.

Tags: Methods subclasses articles content functions examples objects appropriate special personnel just need ideas new knowledge more concepts steps knowledge knowledge points articles systems Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux OPPO Reno Redmi MariaDB NVidia