Voting

: zero plus five?
(Example: nine)

The Note You're Voting On

rafal at pawlukiewicz dot com
6 years ago
SplObjectStorage class can be nicely used in Observer pattern, for example:

<?php
class Subject implements \SplSubject
{
private
$observers;

public function
__construct()
{
$this->observers = new \SplObjectStorage;
}

public function
attach(\SplObserver $observer)
{
$this->observers->attach($observer);
}

public function
detach(\SplObserver $observer)
{
$this->observers->detach($observer);
}

public function
notify()
{
foreach (
$this->observers as $observer) {
$observer->update($this);
}
}
}
?>

<< Back to user notes page

To Top