Event driven programming in PHP - Introduction




PHP doesn't currently support events, although there are functions in PHP that have similar functionality in their implementation, like the xml_set_element_handler function for example.

It is quite tricky to fully incorporate events into PHP. The biggest challenge however is to provide sufficient abstraction that would make it simple(and viable) to use. Potentially forcing us to rethink our web application architecture.

Just to get everyone up to par, an event offers functionality that exposes certain occurances within an object. Enabling a developer to handle these occurances(onload, onclick, onkeydown etc).

Events as seen in Javascript

 
window.onload = function()
{
    alert("Welcome");
}
 
window.onclick = function()
{
    alert("You clicked");
}
 

Typically developers will "subscribe" to an event by assigning some method(s) that must be executed once the event gets raised. Several different mechanisms exist for raising these events, such as monitoring sensor outputs, user actions (keyboard, mouse etc) and requests from browsers (like you'd see in web forms via ASP.net).

Since we're going to be concentrating on PHP in this article, our focus is web technology (Javascript, HTML,CSS, PHP)

We'll need to write some code to house events server side and pass events from the browser which essentially harbors our GUI. While providing some kind of abstraction; provide server side versions of HTML objects and events.

Lets have a look at what a few possible uses might be if we were to use events.

Building flexible controls >>



No Entries Found

Post comment

Name *
Email
Title
Body *
Security code
*
* Required fields