observers = new \SplObjectStorage(); } public function attach(\SplObserver $observer) { $this->observers->attach($observer); } public function detach(\SplObserver $observer) { $this->observers->detach($observer); } public function changeEmail(string $email) { $this->email = $email; $this->notify(); } public function notify() { /** @var \SplObserver $observer */ foreach ($this->observers as $observer) { $observer->update($this); } } }