数组形式访问对象-成都快上网建站

数组形式访问对象

//数组形式访问对对象
/**
* 1.通过继承PHP内置接口ArrayAccess来实现
* 2.必须实现方法:offsetExists,offsetGet,offsetSet,offsetUnset;
*/
classNewObjectimplementsArrayAccess
{
   /**
    * 检查一个偏移位置是否存在
    *@parammixed $offset
    *@returnbool
    */
   public functionoffsetExists($offset)
   {
       //处理逻辑代码
   }


   /**
    * 获取一个偏移位置的值
    *@parammixed $offset
    *@returnnull
    */
   public functionoffsetGet($offset)
   {
       //处理逻辑代码
   }


   /**
    * 设置一个偏移位置的值
    *@parammixed $offset
    *@parammixed $value
    */
   public functionoffsetSet($offset,$value)
   {
       //处理逻辑代码
   }

   /**
    * 复位一个偏移位置的值
    *@parammixed $offset
    *@returnnull
    */
   public functionoffsetUnset($offset)
   {
       //处理逻辑代码
   }
}

文章标题:数组形式访问对象
文章网址:http://kswjz.com/article/gcsdjh.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流