批改状态:合格
老师批语:看来6月10日前你是写不完了, 除非加班写,祝成功
<?php$a = 10;$b = 20;
<?phpecho "$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>";

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号