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, if you need it, you can refer to the following example to describe the inheritance and usage of PHP object-oriented programming language (OOP. We will share this with you for your reference. The details are as follows:
Name = $ name; $ this-> sex = $ sex; $ this-> age = $ age;} function say () {echo $ this-> name. "speak
";} Function run () {echo" is walking ·
";}} Class Student extends Person {var $ school; function _ construct ($ name =" ", $ sex =" male ", $ age = 22, $ school = "") {parent ::__ construct ($ name, $ sex, $ age); $ this-> school = $ school;} function study () {echo $ this-> name. "In Progress ". $ this-> school. "Learning
";}} Class Teacher extends Student {var $ wage; function teaching () {echo $ this-> name. "In Progress ". $ this-> school. "Teaching, the monthly salary is ". $ this-> wage."
";}}$ Teacher1 = new Teacher (" kaifu "," male ", 22); $ teacher1-> school =" edu "; $ teacher1-> wage = 4000; $ teacher1-> say (); $ teacher1-> study (); $ teacher1-> teaching ();?>
Result:
Kaifu is talking. kaifu is learning from edu. kaifu is teaching at edu. the monthly salary is 4000.
I hope this article will help you with PHP programming.
For more PHP object-oriented programming examples of OOP inheritance usage, please follow the PHP Chinese network!