News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Eric Adams' Blog:
Implementing the Observer Pattern with SplObserver and SplSubject
June 30, 2010 @ 12:43:34

In a recent post from Eric Adams, he shows how to use the SplObserver and SplSubject components of the Standard PHP Library (SPL) to make an implementation of the observer pattern for more reusable code.

As PHP applications grow into complex object-oriented systems, developers look to create centralized components to execute repetitive tasks. These include logging, emailing, redirects, and more. The Observer pattern is a commonly used design pattern to hook such components into an application during runtime, thereby making them reusable. Since PHP 5.1, there are two interfaces built into the Standard PHP Library (SPL) that can be implemented to use the Observer pattern in your application. They are SplSubject, and SplObserver.

He shows how to use them in an example of a custom error handler class that extends the SplSubject with its attach, detach and notify methods as well as logger and mailer classes that will use it to handle their exceptions.

0 comments voice your opinion now!
splobserver splsibject tutorial observer designpattern


blog comments powered by Disqus

Similar Posts

Marcelo Gornstein's Blog: Sniffing in PHP using libpcap: Thank you SWIG!

SpinDrop.us: Using Zend Search Lucene in a symfony app

Matthew Weier O'Phinney's Blog: Creating Re-Usable Zend_Application Resource Plugins

SitePoint PHP Blog: How to Run Multiple Versions of PHP on One Server

DevShed: Working with Images and Text Flows in PDF Files with PHP 5


Community Events





Don't see your event here?
Let us know!


tool install podcast security community interview composer library version voicesoftheelephpant update symfony language package introduction opinion laravel release framework series

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework