Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6196291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:37:03+00:00 2026-05-24T03:37:03+00:00

I am planning on working on a game that has a PHP back-end to

  • 0

I am planning on working on a game that has a PHP back-end to communicate with the data repository. I was thinking about it and concluded that the best design paradigm to follow for our game would be event driven. I am looking to have an achievement system (similar to the badges system of this website) and basically I would like to be able to hook these “achievement checks” into a number of different events that occur in the game. ie:

When a user does action X hook Y is fired and all attached functions are called to check against an achievement requirement.

In structuring the architecture like this I will allow for new achievements to be added easily as all I will have to do is add the checking function to the proper hook and everything else will fall into place.

I’m not sure if this is a great explanation of what I intend to do, but in any case I am looking for the following:

  1. Good reference material on how to code an event-driven application
  2. Code snippet(s) showing how to put a “hook” in a function in PHP
  3. Code snippet(s) showing how to attach a function to the “hook” mentioned in point 2

I have a few ideas as to how to accomplish 2) and 3) but I was hoping that somebody well-versed in the matter could shed some light on best practices.

Thank you in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T03:37:04+00:00Added an answer on May 24, 2026 at 3:37 am

    Good reference material on how to code an event-driven application

    You can either do this with “dumb” callbacks (Demo):

    class Hooks
    {
        private $hooks;
        public function __construct()
        {
            $this->hooks = array();
        }
        public function add($name, $callback) {
            // callback parameters must be at least syntactically
            // correct when added.
            if (!is_callable($callback, true))
            {
                throw new InvalidArgumentException(sprintf('Invalid callback: %s.', print_r($callback, true)));
            }
            $this->hooks[$name][] = $callback;
        }
        public function getCallbacks($name)
        {
            return isset($this->hooks[$name]) ? $this->hooks[$name] : array();
        }
        public function fire($name)
        {
            foreach($this->getCallbacks($name) as $callback)
            {
                // prevent fatal errors, do your own warning or
                // exception here as you need it.
                if (!is_callable($callback))
                    continue;
    
                call_user_func($callback);
            }
        }
    }
    
    $hooks = new Hooks;
    $hooks->add('event', function() {echo 'morally disputed.';});
    $hooks->add('event', function() {echo 'explicitly called.';});
    $hooks->fire('event');
    

    Or implementing a pattern often used in event-driven applications: Observer Pattern.

    Code snippet(s) showing how to put a “hook” in a function in PHP

    The manual link above (callbacks can be stored into a variable) and some PHP code examples for the Observer Pattern.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a data validator package for PHP (mostly as an exercise in
So the problem I am having has not actually happened yet. I am planning
I have implemented Conway's Game of Life problem in Java swing. Everything is working
I'm planning out adding Facebook integration to a web app I'm working on. For
I'm working in an application where a third-party has exposed two services one is
I'm working on a project where I need to take a single horizontal or
i wish to create a multiplayer game facebook app. a game will have 1
I am working in Finance Industry. We want to roll out Database hit for
I'm working on a prototype EF application, using POCOs. Mainly as an introduction to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.