O'Reilly logo

Pro PHP: Patterns, Frameworks, Testing and More by Kevin McArthur

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required