- 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實現動態屬性
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.