What is the method of calling the parent class constructor in php?

coldplay.xixi
Release: 2023-03-03 22:16:01
Original
3698 people have browsed it

php calls the parent class constructor: first, the parent class constructs the function first, the code is [public function __construct()]; then use [parent::__construct()] to call the parent class constructor.

What is the method of calling the parent class constructor in php?

php calls the parent class constructor method:

1. Use the function [parent::__construct()] to call The parent class constructor

code is as follows;

"; parent::__construct(); //调用父类构造函数 } } $childClass = new ChildClass(); //对类的实例化 ?>
Copy after login

2. Running results

Constructor of the subclass

Constructor of the parent class

Related learning recommendations:php programming(video)

The above is the detailed content of What is the method of calling the parent class constructor in php?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!