Skip to content

Instantly share code, notes, and snippets.

@lotfio
Created October 13, 2019 10:54
Show Gist options
  • Save lotfio/32922bdeb1170e52883387e3646a10ad to your computer and use it in GitHub Desktop.
Save lotfio/32922bdeb1170e52883387e3646a10ad to your computer and use it in GitHub Desktop.
PHP event example
<?php
class Event
{
public function fire($event, $params = NULL)
{
return call_user_func($this->{"on".ucfirst($event)});
}
}
$event = new Event;
// define events
$event->onLogin = function()
{
return "Yes logged in";
};
// define events
$event->onLogOut = function()
{
return "Yes logged out";
};
// fire the event
echo $event->fire("login");
echo $event->fire("logOut");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment