PHP ArrayAccess and ArrayObject

In very simple terms, ArrayAccess is an interface, which you can implement in your own objects; ArrayObject, on the other hand, is a class, which you can either use or extend.

ArrayAccess is an interface built in to PHP which lets you dictate how PHP behaves when an object has array syntax (square brackets) attached to it. Interfaces are collections of function prototypes that we can use as templates for our own code. If you read the manual page for ArrayAccess, it shows four functions:

ArrayAccess {
/* Methods */
abstract public boolean offsetExists ( mixed $offset )
abstract public mixed offsetGet ( mixed $offset )
abstract public void offsetSet ( mixed $offset , mixed $value )
abstract public void offsetUnset ( mixed $offset )
}

ArrayObject is an object, you can implement and extend it as you usually would. It implements a bunch of useful interfaces and wraps them up into an object. For creating an object to look a lot like an array, take a look at ArrayObject! It implements ArrayAccess as we saw above, but also Countable, Traversable, and others.

ArrayAccess vs ArrayObject