- class membershipuser
- {
- public $userid;
- public $attributes;
- function __construct()
- {
- }
- function getuser($userid)
- {
- $this->userid = $userid;
- $this->username = "123123"; //这里的username可以用动态实现不需要定义
- }
- 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);
phpclass实现动态属性
最新推荐文章于 2024-05-04 14:22:59 发布