Writing an Event System in PHP
In this tutorial you will learn how to create and implement an event system in PHP. You will be able to integrate it with your own web application or framework.
What is an event system?
An event system is a way to call prefined functions at a specified time in your application code. It’s main use is to allow developers to add functionality to your code without modifying the original source. Directly editing the source code of an application is proven not to work because every time the software gets updated, the changes made to the source get overwritten. By offering an event system in your application developers will be able to write plugin style code which will get executed at a specified time in the main application code. This makes your platform easier to develop for and offers a low entry level for coders wanting to add functionality themselves.
Overview of the system
event::$events is a static variable (array) which holds all of the registered events and associated Closure objects.
event::register(‘eventName’, function($args){}) accepts two arguments. The first being the name of the event and the second being a Closure object which will be called when the event is fired.…


