Correcting teacher:PHPz
Correction status:qualified
Teacher's comments:
实例源码
<?php
include __DIR__.DIRECTORY_SEPARATOR.'0812text\text.php';
echo $textdata.'<hr>';
// E:\Users\RAJA\Desktop\test\xuexiphp\0812\
class Users {
public $username;
public $email;
private $password;
public $name ='zhong';
private $age = '18';
public static $text;
public function __get($m)
{
// 筛选过滤,给条件方法,私有变量可起到隐私作用
if($m === 'age') {
if($this -> name === 'HU'){
return $this->$m;
} else {
return $this->$m + 10;
}
}else {
return $this ->$m;
}
}
public function __set($n,$value)
{
return $this -> password = $value;
return $this -> name = $value;
}
public function __construct($x,$y,$z,$q='111')
{
// 初始化
$this -> username = $x;
$this -> email = $y;
$this -> password = $z;
self::$text = $q;
}
};
$user = new Users('wang',$textdata,'12345678');
echo $user->username.'<hr>';
echo $user->email.'<hr>';
echo $user->password.'<hr>';
echo $user->age.'<hr>';
$user->password = '09873';
echo $user->password.'<hr>';
$user->name = 'HU';
echo $user->age.'<hr>';
$user2 = new Users('zhong','wh@qq.com','iusdhfa sdf');
echo $user2->username.'<hr>';
echo $user2->email.'<hr>';
echo $user2->password.'<hr>';
echo $user2::$text='999';
// 面向对象的编程理解:类相当于一个方法,__get获取类内部的私有变量(可条件判断根据值的不同给定不同的方法操作),
// __set()修改类内部变量的值(也可等于数据库获取的值),__construct()对象构造器,通过传参,
// 使用外部变量赋值,来进行外部数据获取,在特定的类中进行数据处理;
实例结果: