CHAPTER 12SPL Array Overloading

Array overloading is the process of using an object as an array. Some people coming from different language backgrounds may know this ability by another name: indexers.

The material in this chapter will help you learn how to create objects that can have their contents read and manipulated using the standard array syntax.

Introducing ArrayAccess

The ArrayAccess interface enables your objects to behave as arrays. It consists of four methods, as listed in Table 12-1.

Table 12-1. ArrayAccess Methods

Method Description
offsetSet() Sets an offset for array access. Takes two parameters: an offset to be used as the array index and a value to assign.
offsetGet() Gets the associated value given a specified offset. ...

Get Pro PHP: Patterns, Frameworks, Testing and More now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.