concept
1. The construction method __construct() is a special method unique to the structure.
2. This method is specified by the system. Developers only need to write it once when defining it. After the class with a constructor method instantiates the object, the object will automatically call it.
grammar:
function __construct(arg1,arg2,...) { ... }
Note on usage
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 automatically called.
If the __construct method of a subclass wants to call the __construct method of the parent class, the constructor of the parent class must be called 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");
The above is an introduction to the PHP construction method __construct(). I hope it will be helpful to everyone.