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 6382939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:35:16+00:00 2026-05-25T02:35:16+00:00

I have a PHP web application where I’ve made a little module system, that

  • 0

I have a PHP web application where I’ve made a little module system, that basically works like this:

Each module has it’s own file, filename can be anything, but does not matter (for the sake of logic I named the filename is the same as the module name). The content of a module could look like this:

$MODULE["name"] = "some_module";
$MODULE["description"] = "This module does some things";
$MODULE["required"] = false;
$MODULE["module_specific_var"] = some_function_that_returns_some_value();

I have a global $MODULES array where I read all modules into:

foreach ($modules_list as $module_filename){
  if (isset($MODULE)) unset($MODULE);
  include($module_path."/".$module_filename);
  $MODULES[$MODULE["name"]] = $MODULE;
}

Now this is pretty simple and have been more than enough for my needs… Until now… Now I need a module specific function and that doesn’t work with associative arrays (as far as I know of). What I’d like is something along the lines of being able to call $MODULES["name_of_module"]["name_of_module_specific_function"]();

I know this can be achieved with function references and as long as I use include() for each module, any functions defined in the module files will be available in global space – this may cause naming issues though, so bad idea.

Alternatively I make each module a class, something along the lines of:

class module_name {
  var $name = "some_module";
  var $description = "This module does some things";
  var $required = false;
  var $module_specific_var = some_function_that_returns_some_value();
  function module_specific_function(){
  }
}

Since I’ve already got a fair bit of code, my question is – is there an alternative to making all the modules class based, which avoids both the problem of name conflicts and allows me to keep the current module system fairly intact?

  • 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-25T02:35:17+00:00Added an answer on May 25, 2026 at 2:35 am

    OO is the way to go here. Make a Module base class, and extend that if you need module specific functions.

    If you map the class names to your file names, you can even use an autoloader so you won’t have to include() everything. It would also be nice to have a central Singleton class to keep track of your module instances (to avoid having to use globals, which is a deprecated practice).

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

Sidebar

Related Questions

I have a PHP web application. This application works on Windows server, but it
I would like to make a web application (PHP) that will have overlay container
I have a PHP web application on an intranet that can extract the IP
I have this PHP web application. It has a link to an XML file
I have a php web application that uses big cookies to store a lot
I have a PHP web site that has two directories: An application directory and
I have a simple page in a PHP/MySQL web application that lets admin users
I have a PHP Web application that consumes a Web Service using PHP's native
I have a PHP web application that needs to call a function in a
We have a web application written in PHP that exports MySQL query results 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.