Home  >  Article  >  Backend Development  >  Detailed explanation of OOP inheritance usage in PHP object-oriented programming

Detailed explanation of OOP inheritance usage in PHP object-oriented programming

墨辰丷
墨辰丷Original
2018-05-29 10:23:011276browse

This article mainly introduces the usage of OOP inheritance in PHP object-oriented programming, and analyzes the definition and inheritance usage of PHP classes in the form of simple examples. Friends in need can refer to it

The examples in this article describe PHP OOP inheritance usage in object-oriented programming. Share it with everyone for your reference, the details are as follows:

name = $name;
    $this->sex = $sex;
    $this->age = $age;
  }
  function say() {
    echo $this->name . "在说话
"; } function run() { echo "在走路·
"; } } class Student extends Person { var $school; function __construct($name = "", $sex = "男", $age = 22,$school="") { parent::__construct($name,$sex,$age); $this->school = $school; } function study() { echo $this->name."正在".$this->school."学习
"; } } class Teacher extends Student { var $wage; function teaching() { echo $this->name."正在".$this->school."教学,每月工资为".$this->wage."
"; } } $teacher1 = new Teacher("kaifu","男",22); $teacher1->school = "edu"; $teacher1->wage = 4000; $teacher1->say(); $teacher1->study(); $teacher1->teaching(); ?>

Result:

kaifu在说话
kaifu正在edu学习
kaifu正在edu教学,每月工资为4000

The above is the entire content of this article, I hope it will be helpful to everyone's study.


Related recommendations:

PHP collection class snoopy example introduction

Post static binding after PHP OOP

php uses snoopy to share examples of simulated login with curl

The above is the detailed content of Detailed explanation of OOP inheritance usage in PHP object-oriented programming. For more information, please follow other related articles on the PHP Chinese website!

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