
php教程--案例28(体验类与对象)
发布日期:2021-05-06 21:10:31
浏览次数:29
分类:原创文章
本文共 734 字,大约阅读时间需要 2 分钟。
<?php//case 28 体验类与对象//声明类class student1{ public $name; public $student_id; public $age; public $gender; public function introduce() { echo "大家好,我是{$this->name},今年{$this->age}岁。<br>我的学号是{$this->student_id},很高兴认识大家。<br>"; } public function study($time) { $time = date("Y-m-d H:i:s",$time); echo "当前时间为{$time},学习中,请勿打扰......<br>"; }}//实例化$stu = new student1();$stu->name = '小明';$stu->student_id = '20200111178';$stu->age = 18;$stu->gender = '男性';$stu2 = new student1();$stu2->name = '小红';$stu2->student_id = '20200111179';$stu2->age = 19;$stu2->gender = '女性';echo '<pre>';var_dump($stu,$stu2);echo '</pre>';$stu->introduce();$stu->study(time());$stu2->introduce();$stu2->study(time());