当前位置:Gxlcms > PHP教程 > arrayAccess的接口使用,arrayaccess接口_PHP教程

arrayAccess的接口使用,arrayaccess接口_PHP教程

时间:2021-07-01 10:21:17 帮助过:4人阅读

arrayAccess的接口使用,arrayaccess接口


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'];
    
    
    
    

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/965028.htmlTechArticlearrayAccess的接口使用,arrayaccess接口 ? php // get the methods instance of ArrayAccess //get the properties instance of ArrayAccess $reflection = new ReflectionClass('Arra...

人气教程排行