How to implement Class inheritance by php
This article is about how php implements class inheritance. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Description:
1. Inheritance makes the code more hierarchical
two。 The subclass inherits the properties and methods of the parent class and achieves code reusability.
3. Using the extends keyword to implement inheritance
4. Classification and subcategories are relative.
Syntax:
Class subclass extends parent class {
}
/ / parent class: class Person {public function show () {echo 'this is a human';}} / / the subclass inherits the parent class class Student extends Person {} $stu = new Student;$stu- > show () / / the above code execution process: / / the first step is to find show () in Student, if it is found, it will be called, and the parent class cannot be found. / / the second step is to query show () in the Person class and call. Thank you for reading! This is the end of this article on "how to achieve class inheritance in php". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!