当前位置:网站首页>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
?>
边栏推荐
- Balsamiq wireframes free installation
- 线程池概述
- The Hong Kong Stock Exchange learned from US stocks and pushed spac: the follow-up of many PE companies could not hide the embarrassment of the world's worst stock market
- "Simple" infinite magic cube
- idea開發工具常用的插件合集匯總
- Here comes a new chapter in the series of data conversion when exporting with easyexcel!
- 青训营--数据库实操项目
- [paper translation] gcnet: non local networks meet squeeze exception networks and beyond
- 5g market trend in 2020
- php获取cpu使用率、硬盘使用、内存使用
猜你喜欢

Reading notes of cgnf: conditional graph neural fields

【pyinstaller】_ get_ sysconfigdata_ name() missing 1 required positional argument: ‘check_ exists‘

Appnuim environment configuration and basic knowledge

测试 - 用例篇

RGB 无限立方体(高级版)

【论文翻译】GCNet: Non-local Networks Meet Squeeze-Excitation Networks and Beyond

Importation de studio visuel

Centos8 installation mysql8.0.22 tutorial

Lantern Festival gift - plant vs zombie game (realized by Matlab)
![[technical notes-08]](/img/52/0aff21b01ba7adbfcdb597d1aa85f9.png)
[technical notes-08]
随机推荐
VSCode paste image插件保存图片路径设置
Test case
Taskbar explicit / implicit toggle function
Win10 copy files, save files... All need administrator permission, solution
Matplotlib double Y axis + adjust legend position
c语言中的几个关键字
2022-2-15 learning xiangniuke project - Section 8 check login status
PHP 开发与测试 Webservice(SOAP)-Win
Usage record of vector
在线音乐播放器app
文件包含漏洞(一)
1035 Password
With an amount of $50billion, amd completed the acquisition of Xilinx
《CGNF: CONDITIONAL GRAPH NEURAL FIELDS》阅读笔记
I want to understand the swift code before I learn it. I understand it
Zzuli:1067 faulty odometer
[personal test] copy and paste code between VirtualBox virtual machine and local
Zzuli:1066 character classification statistics
2022-2-14 learning xiangniuke project - Section 7 account setting
Visual Studio导入