本文介绍了PHP,SPL,ArrayAccess接口界面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解背后了ArrayAccess接口,

I am trying to understand the idea behind ArrayAccess Interface,

我不明白每种方法左右,如果这些方法(函数)是内置的功能和ArrayAccess接口接口(也内置)不仅是确保我要实现这些内置方法(函数)

I dont understand what each method is about, If those methods(functions) are "built in" functions and ArrayAccess Interface(also "built in") is only "make sure" i am going to implement those "built in" methods(functions)

我想了解什么呢每个thoes功能与我们的code幕后花絮做的事情。

I am trying to understand what does each of thoes functions is doing with our code "Behind the scenes".

function offsetSet($offset, $value);
function offsetGet($offset);
function offsetUnset($offset);
function offsetExists($offset);

如果我明白了ArrayAccess一个内置接口,含密封实现,当我们执行他们,我们只实现内置函数thoes参考,我会很高兴,如果有人可以帮助我得到这个权利。

If i understand ArrayAccess is a Built In interface that Containing seals to implement, when we implement them we only implement references to thoes built in functions, I will be happy if some one can please help me get this right.

推荐答案

如果您实现该接口,那么对象就像一个数组。例如,如果 $ foo的是一个类的实例,它实现 ArrayAccess接口

If you implement that interface, then the object acts like an array. e.g., if $foo is an instance of a class that implements ArrayAccess:

$ foo的['酒吧'] = 42 通话 offsetSet('酒吧',42)

回声$ foo的['酒吧'] 通话 offsetGet('巴')

未设置($ foo的['酒吧'])通话 offsetUnset('巴')

使用isset($ foo的['酒吧'])通话 offsetExists('巴')

您从来没有显式调用功能失调*自己。当您访问对象的数组正好暗示。

You never explicitly call the functions offset* yourself. It happens implicitly when you access the object as an array.

这篇关于PHP,SPL,ArrayAccess接口界面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 18:26