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

  • SEARCH
  • Home
  • 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 960635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:12:48+00:00 2026-05-16T01:12:48+00:00

I was thinking about implementing a logic similar to observer pattern on my website,

  • 0

I was thinking about implementing a logic similar to observer pattern on my website, for implementing hooks.

What I am looking for is something similar to this Best way to allow plugins for a PHP application

However the code there is too limited, as I cant attach multiple hooks to same listener.

I am clueless about how to amplify that code to make it able to listen multiple actions at one event.

Thank You

  • 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-16T01:12:49+00:00Added an answer on May 16, 2026 at 1:12 am

    You can do as ircmaxell suggests: add hooks. But clearly, the information he gave was not enough for you.

    If you like learning by example, you may look at the CMS Drupal, wich is not OOP, but uses the observer pattern, called hooks all over the place to allow a modular design.

    A hook works as follows:

    • a piece of php looks for the existence of a specially named function.
    • If that exists, call it and use its output (or do nothing with it)

    For example:

    • Just before an article gets saved in Drupal, the article-system calls the hook_insert
    • Every module that has a function in the name of ModuleName_insert, will see that function being called. Example: pirate.module may have a function pirate_insert(). The article system makes a roundtrip along all the modules and sees if ModuleName_insert exists. It will pass by pirate module and finds pirate_insert(). It will then call that function (and pass some arguments along too). As such, allowing the pirate.module to change the article just before insertation (or fire some actions, such as turning the body-text into pirate-speek).

    The magic happens in so called user_callbacks. An example:

    $hook = 'insert'
    foreach (module_implements($hook) as $module) {
      $function = $module .'_'. $hook;
      $result = call_user_func_array($function, $args);
    }
    

    And the function module_implements might look something like:

    $list = module_list(FALSE, TRUE, $sort); //looks for files that are considered "modules" or "addons".
    foreach ($list as $module) {
      if (function_exists($module.'_'.$hook)) { //see if the module has the hook 'registered'
        $implementations[$hook][] = $module; //if so: add it to a list with functions to be called.
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 465k
  • Answers 465k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you instantiate and store the UITabBarController in your App… May 16, 2026 at 1:14 am
  • Editorial Team
    Editorial Team added an answer If you're trying to open a key from a remote… May 16, 2026 at 1:14 am
  • Editorial Team
    Editorial Team added an answer UIScrollView tries to determine what kind of interaction the user… May 16, 2026 at 1:14 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.