As @zerkms noted, this is possible with any class that implements an interface ArrayAccess.
The easiest way is to use a class ArrayObjectthat is native to PHP and already implements an interface ArrayAccessthat can be used on its own:
$object = new ArrayObject;
...
$value= $object[$index];
Or advanced:
class MyArrayLikeClass extends ArrayObject {
...
}
$object = new MyArrayLikeClass;
...
$value= $object[$index];
ArrayObject - ArrayAccess , IteratorAggregate, (.. foreach).