Created
October 13, 2019 10:54
-
-
Save lotfio/32922bdeb1170e52883387e3646a10ad to your computer and use it in GitHub Desktop.
PHP event example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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