首页 > 数据库技术 > 详细

arrayAccess的接口使用

时间:2015-03-05 18:46:47      阅读:350      评论:0      收藏:0      [点我收藏+]
<?php
    //get the methods instance of ArrayAccess
    //get the properties instance of ArrayAccess
    $reflection = new ReflectionClass(‘ArrayAccess‘);
    //var_dump($reflection->getMethods());
    //var_dump($reflection->getProperties());
    
    class dbTypes implements ArrayAccess{
        private $dbtypes = array();
        
        //判定是否存在
        public function offsetExists($offset){
            return isset($this->dbtypes[$offset]) ? true : false;
        }
        //获取一个值
        public function offsetGet($offset){
            if($this->offsetExists($offset)){
                return $this->dbtypes[$offset];
            }else{
                return null;
            }
        }
        //设置一个值
        public function offsetSet($offset,$value){
                $this->dbtypes[$offset] = $value;
        }
        //删除一个值
        public function offsetUnset($offset){
            unset($this->dbtypes[$offset]);
        }
    }
    
    $types = new dbTypes();
    echo $types[‘nosql‘];
    
    
    
    

 

arrayAccess的接口使用

原文:http://www.cnblogs.com/ikasa007/p/4316147.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!