You can create something like an event handling class in PHP:
class Event { protected $_eventCallbacks = array(); function addEventCallback($callback) { $this->_eventCallbacks[$callback] = $callback; } function removeEventCallback($callback){ if(isset($this->_eventCallbacks[$callback])){ unset ($this->_eventCallbacks[$callback]); } } function cleanEventCallback(){ foreach ($this->_eventCallbacks as $callback) { unset ($callback); } } function fireEvent() { foreach ($this->_eventCallbacks as $callback) { call_user_func($callback); } } }
This code was taken from here http://setahost.com/php-events-singletone-and-factory-pattern-application/ This class also has a good example of a modular and sub-modular application.
source share