2.2. The Standard PHP Library
The Standard PHP Library (SPL), developed by Marcus Boerger, is a useful collection of interfaces and classes bundled with PHP as an extension. In PHP 5, this was added as part of the core distribution. The manual states that this set of interfaces and classes is "meant to solve standard problems." At first read, this echoes the explanation given earlier of Design Patterns. Indeed, the library has an assortment of features that does help with your creation of Design Patterns in PHP. Let's review a few of the main players of the SPL to see what you may use in your future pattern-based architecture.
2.2.1. SPL Observer and SPL Subject
The SplObserver and the SplSubject interfaces are an implementation of the Observer Design Pattern. SplSubject contains three method declarations: attach(), detach() and notify(). attach(), and detach() are used to attach objects to the chain of notification and receive a SplObserver object. The notify() function is called whenever an action happens that the chain should be aware of. The SplObserver interface contains one method, update(), which receives only one parameter — an SplSubject object. This should be called whenever the SplSubject's value changes.
This may seem very vague and confusing if you're not familiar with the Observer Design Pattern. However, the main thing to remember is the existence of these methods as you continue on to study the Design Patterns. You may find that using some of these methods may ...
Get Professional PHP Design Patterns 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.