php构造函数的继承方法,php构造函数继承
本文实例讲述了php构造函数的继承方法。分享给大家供大家参考。具体如下:
第一种情况:子类没有定义构造函数时,默认继承。例子:
<?php
class A{
public $name;
function __construct(){
echo $this->name="小强";
}
}
class B extends A{
}
$bb = new B();
?>
输出结果:小强
第二种情况:子类定义了构造函数,则不会被继承。实例:
<?php
class A{
public $name;
function __construct(){
echo $this->name="小强";
}
}
class B extends A{
function __construct(){
echo "BBBBBB子类";
}
}
$bb = new B();
?>
输出结果:BBBBBB子类
第三种情况:如果需要调用父类的构造函数,则可以使用:parent::父类函数 或 父类名::父类函数。
希望本文所述对大家的php程序设计有所帮助。
Statement
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

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Assassin's Creed Shadows: Seashell Riddle Solution
3 weeks agoByDDD
What's New in Windows 11 KB5054979 & How to Fix Update Issues
2 weeks agoByDDD
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version
Recommended: Win version, supports code prompts!

Atom editor mac version download
The most popular open source editor

Dreamweaver Mac version
Visual web development tools






