//Create a class
class Student
{
//define member properties with public declaration, public refers to shared, accessible anywhere
//Name
Public $name = ' lemon ';//Set initial value
//Study No.
Public $no;
//Score
Public $score;
//Member Method
Public function Sing ($songName) {
echo "Students sing {$songName} song";
}
Public function Run () {
echo "Students go jogging";
}
Public function Showself () {
echo "My Name". $this->name. "My study number is {$this->no}, my score is {$this->score}";
$this->sing ("Chengdu");
}
}
class teacher{
Public $name;
Public $no;
Public $course;
Public function Teachbook () {
echo "Teacher will teach";
}
Public function Dance () {
echo "Teacher Can Dance";
}
}
//instanced objects
$student 1 = new Student ();
Echo $student 1->name;
$student 1->name = ' lemon ';
Echo $student 1->name;
$student 1->sing ("state");
echo "
$student 2 = new Student ();
$student 2->name = "Zhang San";
$student 2->no = "1001";
$student 2->score = "";
$student 2->showself ();
include "";//used to refer to class, error warning
require "";//used to refer to class, error will crash
include_once "";//reference only once, multiple references will not error
require_once "";//reference only once, multiple references will not error
PHP Classes and objects