时间:2021-07-01 10:21:17 帮助过:18人阅读
class score{
private $_oUser;
public function __construct($oUser){
$this->_oUser = $oUser;
}
public function add(){
}
public function update(){
}
}
//用戶基類
class BaseUser{
public $userName;
public $password;
function __construct($userName,$password){
$this->userName = $userName;
$this->password = $password;
}
}
//角色類
class Role{
private $userName;
public $roleName;
function __construct($userName,$roleName){
$this->userName = $userName;
$this->roleName = $roleName;
}
function GetRoleUserName()
{
return $this->userName;
}
}
//積分類
class Score{
private $userName;
private $module;
public $score;
function __construct($userName,$module,$score){
$this->userName = $userName;
$this->module = $module;
$this->score = $score;
}
function GetScoreUserName()
{
return $this->userName;
}
function GetScoreModule()
{
return $this->module;
}
}
//用戶類 繼承用戶基類
class User extends BaseUser{
public $role;
public $score;
function __construct($userName,$password,$roleName,$score){
parent::__construct($userName, $password);
$this->role = new Role($userName,$roleName);
$this->score = new Score($userName,"module",$score);
}
}
$user = new User("user9527","123","xiaoming",100);
echo "userName: ".$user->userName;
echo "
";
echo "password: ".$user->password;
echo "
";
echo "roleName: ".$user->role->roleName;
echo "
";
echo "score: ".$user->score->score;
echo "
";
/*
userName: user9527
password: 123
roleName: xiaoming
score: 100
*/
//code end