Correcting teacher:天蓬老师
Correction status:qualified
Teacher's comments:看来6月10日前你是写不完了, 除非加班写,祝成功
<?php
$a = 10;
$b = 20;
<?php
echo "$a $b <br>"; //未载入文件调用
include 'demo1.php';
echo "$a + $b" ;//载入文件后调用
<?php
权限修饰符 class 类名{
类成员;
}
<?php
//定义类
class Gueste{
//定义属性
private $name;
private $gender;
//设置静态方法,通过类名::调用
public static $nation = 'CHINA';
//私有属性外部无法访问,所以提供get/set方法,此处可以通过增加判断,限制非法属性值
function setName($name){
//$this表示当前对象,->成员访问符
$this->name = $name;
}
function gettName(){
return $this->name;
}
function setGender($gender){
$this->gender = $gender;
}
function getGender(){
return $this->gender;
}
}
//实例化类的对象xiaoming
$xiaoming = new Gueste;
//调用成员方法
$xiaoming->setName('小明');
$xiaoming->setGender('男');
//输出对象信息
echo "姓名:".$xiaoming->gettName()."\t"."性别:".$xiaoming->getGender()."\t"."国籍".Gueste::$nation."<br>";