对象 __set __get get_class_methods get_class_vars练习笔记

/**
燕十八 公益PHP培训
课堂地址:YY频道88354001
学习社区:www.zixue.it
**/

/*session_start ();

$_SESSION ['utype'] = isset ( $_GET ['type'] ) ? $_GET ['type'] : FALSE;
class study {
    public $name;
    private $age;
    public $city;
    public $sex;
    function __construct($name, $age, $sex, $city = '') {
        $this->name = $name;
        $this->age = $age;
        $this->sex = $sex;
        $this->city = $city;
    }
    function say() {
        echo "我的名子是:" . $this->name . "我的年龄是:" . $this->age;
    }
    function __set($k, $v) {
        if (trim ( $_SESSION ['utype'] ) == 'admin') {
            $this->$k = $v;
        } else {
            die ( "你没权限操作" );
        }
    }
    function __get($varName) {
        if (trim ( $_SESSION ['utype'] ) == 'teacher') {
            return $this->$varName;
        } else {
            return "保密";
        }
    }
}*/
/*$lisi = new study();
$lisi->age=55;
$lisi->say();*/
/*$wangwu = new study ( "王五", "33", "男", "上海" );
echo "<table border=1 cellpadding=0 cellspacing=0>";
echo "<tr><td>名称</td><td>年龄</td><td>性别</td><td>城市</td></tr>";
echo "<tr><td>{$wangwu->name}</td><td>{$wangwu->age}</td><td>{$wangwu->sex}</td><td>{$wangwu->city}</td></tr>";
echo "</table>";*/

/*class teacher {
    private $name;
    private $age;
    private $sex;
    private $classType;
    private $access;
    function __construct($name, $age, $sex, $classType, $access) {
        $this->name = $name;
        $this->age = $age;
        $this->sex = $sex;
        $this->classType = $classType;
        $this->access = $this->access($access);
    }
    private function access($access){
        if(!is_array($access))return FALSE;
        $methodArr = get_class_methods(__CLASS__);
        foreach ($access as $v){
            if(!in_array($v, $methodArr)){
                die("权限配置错误,类中没有此方法");
            }
        }
        $publicAccess = array("say","eat");
        return array_merge($access,$publicAccess);
    }
    public function chuck(){
        $action = isset($_GET['a'])?$_GET['a']:'index';
        if(!in_array($action,$this->access)) die("你没有权限操作");
        $this->$action();
    }
    function say() {
        echo "姓名:{$this->name},年龄:{$this->age},性别:{$this->sex},课程:{$this->classType}<br/>";
    }
    function eat() {
        echo "{$this->name}在吃饭";
    }
    function open() {
            echo "{$this->name}开门";
    }
    function money() {
            echo "{$this->name}查看后盾网帐户";   
    }
}
$libo = new teacher ( "李波", 32, "男", "jquery", array ('money'));
$libo->chuck();*/

/*class a{
    public $a1;
    private $a2;
    private $a3;
    public static  function get_vars(){
        return get_class_vars(__CLASS__);
    }
}*/

posted on 2012-12-14 12:10  可米可面  阅读(159)  评论(0)    收藏  举报