php fire an event

Solutions on MaxInterview for php fire an event by the best coders in the world

showing results for - "php fire an event"
Mathieu
20 Feb 2017
1class Test {
2
3    protected $listeners;
4
5    public function __construct() {
6        $this->listeners = array();
7    }
8
9    private function a() {
10        echo 'something';
11    }
12
13    private function b() {
14        echo 'something else';
15    }
16
17    public function __call($fname, $args) {
18        call_user_func_array(array($this, $fname), $args);
19        foreach($this->listeners as $listener) {
20            $listener->notify('fname was called');
21        }
22    }
23
24    public function addListener(Listener $listener) {
25        $this->listeners[]= $listener;
26    }
27}