Correction status:qualified
Teacher's comments:
类文件:
./class/Admin.php
<?php /** * Created by PhpStorm. * User: 清雨 * Date: 2018/5/3 * Time: 8:50 */ class Admin { private $name; private $age; public function __construct($name,$age) { $this -> name = $name; $this -> age = $age; } public function __get($name) { $msg = null; if (isset($this->$name)) { $msg = $this ->$name; } elseif (isset($this->data[$name])){ $msg = $this -> data[$name]; } else { $msg = '无此属性'; } return $msg; } public function __set($name, $value) { if (isset($this ->$name)){ $this -> $name = $value; } else { $this->data[$name] = $value; } } }
点击 "运行实例" 按钮查看在线实例
index.php
<?php /** * Created by PhpStorm. * User: 清雨 * Date: 2018/5/3 * Time: 9:12 */ require './class/Admin.php'; $admin = new admin('张无忌',31); echo '姓名:',$admin ->name.'<br>'; echo '年龄:',$admin ->age; echo '<hr>'; $admin -> name = '金毛狮王'; $admin -> age = 60; echo '姓名:',$admin ->name.'<br>'; echo '年龄:',$admin ->age;
点击 "运行实例" 按钮查看在线实例
效果图: