·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设开发 >> php网站开发 >> arrayAccess的接口使用

arrayAccess的接口使用

作者:佚名      php网站开发编辑:admin      更新时间:2022-07-23
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'];