当前位置:网站首页>PHP parent
PHP parent
2022-07-02 05:49:00 【Jill__ er】
php parent In object-oriented grammar, it represents “ Parent class ”, In essence, it represents the parent class “ class ”, Not the parent “ object ”, Its usage is “parent:: Properties or methods ;”.
| keyword | meaning | Use location | Examples of use |
|---|---|---|---|
| parent: | Represents the parent class ( This class ) | It must be in one way | parent:: Properties or methods ; |
| self: | Represents the current class | It must be in one way | self:: Static property or method |
| $this: | Represents the object that calls the current method | It must be in one way | $this-> Instance property or method ; |
<?php
class Person{
protected $name;
protected $sex;
protected $age;
function __construct($name="", $sex=" male ", $age=1){
$this->name = $name;
$this->sex = $sex;
$this->age = $age;
}
function say(){
echo " My name : ".$this->name.", Gender : ".$this->sex,", Age : ".$this->age;
}
}
class Student extends Person{
private $school; // Add a school in the student class school Member properties of .
// Override constructor in parent class , Add a school attribute to the parameter list , Used to create objects and initialize member properties
function __construct($name="", $sex=" male ", $age=1, $school=""){
parent::__construct($name, $sex, $age);
$this->school = $school;
}
function stydy(){
echo $this-name." is ".$this->school." Study ";
}
function say(){
parent::say(); // Call the method in the parent class that is overridden by this method
echo " stay ".$this->school." School ";
}
}
$student = new Student(" Zhang San ", " Woman ", "23", "edu");// Create a student object , And pass it to a school name parameter
$student->say();// Call the speaking method in the student class that overrides the parent class
/** The result is : My name : Zhang San , Gender : Woman , Age : 23 stay edu School */
// Be careful : The access permission of the method overridden in the subclass must not be lower than that of the method overridden by the parent class .
// For example, the access permission of the method in the parent class is protected, Then the access permission of the method overridden in the subclass is protected perhaps public
?>
边栏推荐
- 生成二维码
- Determine whether there is an element in the string type
- Cambrian was reduced by Paleozoic venture capital and Zhike shengxun: a total of more than 700million cash
- Usage record of vector
- Typora installation (no need to enter serial number)
- Installation du tutoriel MySQL 8.0.22 par centos8
- Huawei Hongmeng OS, is it OK?
- Fabric. JS background is not affected by viewport transformation
- Appnuim environment configuration and basic knowledge
- With an amount of $50billion, amd completed the acquisition of Xilinx
猜你喜欢

Straighten elements (with transition animation)

kmp思想及模板代码

Centos8 installation mysql8.0.22 tutorial

在线音乐播放器app

Cambrian was reduced by Paleozoic venture capital and Zhike shengxun: a total of more than 700million cash

Balsamiq wireframes free installation

A collection of commonly used plug-ins for idea development tools

File contains vulnerabilities (II)

"Original, excellent and vulgar" in operation and maintenance work

File contains vulnerability (I)
随机推荐
1035 Password
all3dp.com网站中全部Arduino项目(2022.7.1)
【论文翻译】GCNet: Non-local Networks Meet Squeeze-Excitation Networks and Beyond
VSCode paste image插件保存图片路径设置
【LeetCode】Day92-盛最多水的容器
"Simple" infinite magic cube
Youth training camp -- database operation project
Grbl software: basic knowledge of simple explanation
【論文翻譯】GCNet: Non-local Networks Meet Squeeze-Excitation Networks and Beyond
php内的addChild()、addAttribute()函数
all3dp. All Arduino projects in com website (2022.7.1)
Generate QR code
php读文件(读取文件内含有某字符串的指定行)
Résumé de la collection de plug - ins couramment utilisée dans les outils de développement idea
Determine whether there is an element in the string type
[personal test] copy and paste code between VirtualBox virtual machine and local
LCD之MIPI协议的一些说明
Ubuntu 20.04 installing mysql8
Fabric. JS activation input box
RNN recurrent neural network