马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
需要实现的方法
[PHP] 纯文本查看 复制代码
class Foo implements ArrayAccess
{
public function offsetExists( $offset ) {
echo "这里是 offsetExists() 方法 你输入的参数是 {$offset}";
}
public function offsetGet( $offset ) {
echo "这里是 offsetGet() 方法 你输入的参数是 $offset";
}
public function offsetSet( $offset, $value ) {
echo "这里是 offsetSet() 方法 你输入的 {$offset}={$value}";
}
public function offsetUnset( $offset ) {
echo "这里是 offsetUnset() 方法 你输入的参数是 {$offset}";
}
}
类实现了ArrayAccess接口,那么这个类的对象就可以使用$foo['xxx']这种结构了。 $foo['xxx'] 对应调用offsetGet方法。 $foo['xxx'] = 'yyy' 对应调用offsetSet方法。 isset($foo['xxx']) 对应调用offsetExists方法。 unset($foo['xxx']) 对应调用offsetUnset方法。
|