Php
classperson{
Declares a new variable public variable $name, which can be accessed by any class in the package
Public$name; Public$sex; Public$age;
One way to declare this classfunctionsay () {EchoHello
"; Echo"My name is:".$thisName. "
"; Echo"My Sex is:".$thisSex. "
"; } }
Declares a subclass of the new student class as personclassStudentextendsperson{ Public$school; functionStudy () {
Parent:: Can be used to invoke a member method defined in the parent class.
Parent::say ();Echo"My Age is:".$this, age. "
I was ".$thisSchool. School "; } }
Just define P1 as a student class$p 1=NewStudent ();
Assigning values to the Name,sex,age,school property of P1$p 1-name = "Zhang San"; $p 1Sex = "male"; $p 1-age = "18"; $p 1School = "XXX School"; $p 1-study ();?>
The results of the browser output are as follows:
How are you doing!
My name is: Zhang San
My sex is: male
My age is: 18
I am going to school in XXX school.
Here is an example of understanding PHP Object-Oriented programming (OOP), including aspects of the content, you want to be interested in PHP tutorial friends helpful.