Events in PHP. Is it possible?

I come from the C # world and just starting to do a little PHP coding, so I was wondering if events can be used in PHP, or if it is planned to include this function in a future version. If you have a way to simulate this other than this , it would be very appreciated, thanks.

+4
source share
6 answers

There is no such event as C # in PHP, but you can implement an “Observer Pattern” to attach a delegate for notification.

+4
source

The Prado PHP Framework is an event-based platform that you might like, especially since you are coming from C # land and presumably ASP.NET.

Take a look at Quick Start . In particular, take a look at the code in the Management Reference Guide. There are many code examples for you to look and see if this looks like what you are looking for.

+2
source

Stubbles has a pretty nice Event Dispatcher .

+1
source

SPL - The PHP Standard Library provides SplObserver and SplSubject interfaces for implementing an observer pattern in PHP

+1
source

I would also suggest the Prado.

+1
source

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.

0
source

Source: https://habr.com/ru/post/1300477/


All Articles