码迷,mamicode.com
首页 > 编程语言 > 详细

数组形式访问对象

时间:2017-09-04 14:58:50      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:php

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


   /**
    * 获取一个偏移位置的值
    * @param mixed $offset
    * @return null
    */
   public function offsetGet($offset)
   {
       //处理逻辑代码
   }


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

   /**
    * 复位一个偏移位置的值
    * @param mixed $offset
    * @return null
    */
   public function offsetUnset($offset)
   {
       //处理逻辑代码
   }
}


数组形式访问对象

标签:php

原文地址:http://13169797.blog.51cto.com/13159797/1962481

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!