This post covers the SPL section of the OOP chapter when studying for the Zend PHP 7 Certification.

SPL, or Standard PHP Library, is a collection of interfaces and classes that are meant to solve common problems without having to install any external libraries. The library is available and compiled by default in PHP 5.

As seen in the Autoload section, the SPL library provides a spl_autoload_register() function.

One of the classes included in the library is the ArrayIterator class.

This class allows you to unset and modify values and keys while iterating over Arrays and Objects. For example, we can pass an array within the ArrayIterator class

So when would be ideal to use the SPL using classes such as the ArrayIterator class rather than the standard array functions that are present?

One of the big advantages of the SPL is that the PHP foreach function makes a copy of any array passed to it. If you are processing a large amount of data, having the large arrays copied each time you use them in a foreach loop could affect performance.

SPL iterators encapsulate the list and expose visibility to one element at a time making them far more efficient.