PHP object-oriented programming (OOP) inheritance usage example

Source: Internet
Author: User
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.