This article mainly introduced the PHP object-oriented Programming OOP inheritance usage, combined with a simple example of the definition of PHP class and inheritance use method, the need for friends can refer to the next
In this paper, we describe the OOP inheritance usage of PHP object-oriented programming. Share to everyone for your reference, as follows:
<?phpclass person { var $name;//protected var $sex; var $age; function __construct ($name = "", $sex = "male", $age =) { $this->name = $name; $this->sex = $sex; $this->age = $age; } function say () { echo $this->name. "in Speech <br/>"; } function run () { echo "walking <br/>"; }} Class Student extends Person { var $school; function __construct ($name = "", $sex = "male", $age =, $school = "") { parent::__construct ($name, $sex, $age); $this->school = $school; } Function study () { echo $this->name. " Being ". $this->school." Learning <br/> "; }} Class Teacher extends Student { var $wage; function Teaching () { echo $this->name. " Being ". $this->school." Teaching, with a monthly salary of ". $this->wage." <br/> "; }} $teacher 1 = new Teacher ("Kaifu", "Male", "n"), $teacher 1->school = "edu"; $teacher 1->wage = 4000; $teacher 1->say (); $ Teacher1->study (); $teacher 1->teaching ();? >
Results:
Kaifu Speaking Kaifu is Edu learning Kaifu is edu teaching, monthly salary of 4000
The above is the whole content of this article, I hope that everyone's study has helped.