News Feed
Jobs Feed
Sections




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

Zend Developer Zone:
Implementing the Observer Pattern with SplObserver and SplSubject
June 10, 2010 @ 12:15:36

New on the Zend Developer Zone today there's a new tutorial showing you how to set up a script that uses the Observer design pattern with the help of two bits of functionality from the SPL - SplObserver and SplSubject.

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.

They create an exception handler that implements the SplSubject interface (and its "attach", "detach" and "notify" methods) to let the observers of the instance know when an exception is thrown. Code examples are included of both the basic example and a "Mailer" and "Logger" class that can watch the exception handler.

0 comments voice your opinion now!
splobserver splsubject spl tutorial observer designpattern


blog comments powered by Disqus

Similar Posts

Pádraic Brady's Blog: Complex Views with the Zend Framework - Pt 5: The Two-Step View Pattern

DevShed: Refactoring the MySQL Abstraction Class with the Active Record Pattern

DevShed: More Examples of Creating Command Objects with PHP 5

Stoyan Stefanov's Blog: phpBB front-end optimization - 1 hour workshop

Vanessa Vasile's Blog:Using PHP to Extract Image Exif Data


Community Events











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


database hack project security install application hhvm release language component package introduction performance unittest podcast facebook symfony2 composer example framework

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