phpclass实现动态属性
来源:互联网 发布:mac 预览 目录 编辑:程序博客网 时间:2024/04/28 12:17
- class membershipuser
- {
- public $userid;
- public $attributes;
-
- function __construct()
- {
-
- }
- function getuser($userid)
- {
- $this->userid = $userid;
- $this->username = "123123";
- }
-
- function __get($name) { return $this->get($name); }
- function __set($name, $value) { return $this->set($name, $value); }
- function __isset($name) { if ($this->$name!="") return true; else return false; }
- function __unset($name) { return $this->attributes[$name];}
- function get($name) {if (isset($this->attributes[$name])) { return $this->attributes[$name];}}
- function set($name,$values) { $this->attributes[$name] = $values;}
-
- }
- $b = new membershipuser();
- $b->cc = "f1111";
- $b->dd = "d22222";
- echo($b->attributes['cc'].'<br/>');
- echo ($b->attributes['dd'].'<br/>');
- $b->getuser("fd");
- echo($b->username);