An example of understanding PHP object-oriented programming (OOP), object-oriented programming (oop. An example of understanding PHP object-oriented programming (OOP), object-oriented programming (oop? PhpclassPerson {declares a new public variable $ name, which can be accessed by classes in any package. public $ an instance that understands PHP object-oriented programming (OOP) and object-oriented programming (oop)
Class Person {
// Declare a new public variable$ NameCan be accessed by classes in any package
Public $ name; public $ sex; public $ age;
// Declare a method of this class function say () {echo "Hello!
"; Echo" My name is: ". $ this-> name ."
"; Echo" my gender is: ". $ this-> sex ."
";}}
// Declare the new Student class as the child class of Person Student extends Person {public $ school; function study (){
// Parent: Can be used to call the member methods defined in the parent class.
Parent: say (); echo "My age is:". $ this-> age ."
I am going to school at ". $ this-> school. ";}}
// You only need to define P1 as a Student class $ p1 = new Student ();
// Assign $ P1-> name = "Zhangsan"; $ p1-> sex = "male" to the name, sex, age, and school attributes of p1 "; $ p1-> age = "18"; $ p1-> school = "XX school"; $ p1-> study ();?>
The browser output result is as follows:
Hello!
My name is: Zhang San
My gender is: Male
My age is: 18
I am going to school at xx school.
Examples of objective (OOP), object-oriented programming (oop? Php class Person {// declare a new public variable $ name, which can be accessed by classes in any package. public $...