编辑“Student.Class.php”文件
class Student{ public $name; public $sex; public $age; public function Show() { echo "姓名:".($this->name).",性别:".($this->sex).",年龄:".($this->age); } }
编辑“index.php”文件:
// 引用文件 require_once "Student.Class.php"; // 创建对象 $stu = new Student(); $stu->name = "张三"; $stu->sex = "男"; $stu->age = 22; // 打印信息 $stu->Show();
输出:
姓名:张三,性别:男,年龄:22