当前位置:网站首页>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
?>
边栏推荐
- Fabric. JS iText sets the color and background color of the specified text
- Zzuli:1062 greatest common divisor
- Financial portal related information
- Ubuntu 20.04 installing mysql8
- Reflection of the soul of the frame (important knowledge)
- Taskbar explicit / implicit toggle function
- Typora installation (no need to enter serial number)
- "Original, excellent and vulgar" in operation and maintenance work
- Minimum value ruler method for the length of continuous subsequences whose sum is not less than s
- JVM class loading mechanism
猜你喜欢

centos8安装mysql8.0.22教程

Fabric. JS right click menu
![[golang syntax] be careful with the copy of slices](/img/5e/1c82c58940939b94d03377ebdc03e3.jpg)
[golang syntax] be careful with the copy of slices

Lingyunguang rushes to the scientific innovation board: the annual accounts receivable reaches 800million. Dachen and Xiaomi are shareholders

Software testing - concept

【论文翻译】GCNet: Non-local Networks Meet Squeeze-Excitation Networks and Beyond
![[PHP是否安装了 SOAP 扩]对于php实现soap代理的一个常见问题:Class ‘SoapClient‘ not found in PHP的处理方法](/img/25/73f11ab2711ed2cc9f20bc7f9116b6.png)
[PHP是否安装了 SOAP 扩]对于php实现soap代理的一个常见问题:Class ‘SoapClient‘ not found in PHP的处理方法

5g market trend in 2020

Online music player app

Conglin environmental protection rushes to the scientific and Technological Innovation Board: it plans to raise 2billion yuan, with an annual profit of more than 200million yuan
随机推荐
idea開發工具常用的插件合集匯總
1035 Password
生成二维码
JVM class loading mechanism
Usage record of vector
死磕大屏UI,FineReport开发日记
测试 - 用例篇
Generate QR code
[PHP是否安装了 SOAP 扩]对于php实现soap代理的一个常见问题:Class ‘SoapClient‘ not found in PHP的处理方法
软件测试 - 概念篇
Centos8 installation mysql8.0.22 tutorial
c语言中的几个关键字
Fabric. JS free draw rectangle
Zzuli: maximum Convention and minimum common multiple
2022-2-14 learning xiangniuke project - Section 6 displays login information
我所理解的DRM显示框架
How to change the IP address of computer mobile phone simulator
Matplotlib double Y axis + adjust legend position
15 C language advanced dynamic memory management
KMP idea and template code