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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access