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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:32:40+00:00 2026-05-12T07:32:40+00:00

I implemented dynamic loading of plugins in the following way: function processPlugin( $plgFile, $db

  • 0

I implemented dynamic loading of plugins in the following way:

function processPlugin( $plgFile, $db ) {
  require_once( $plgFile );
  $plgin = new PlginImpl();
  $plgin->setDb($db);
  $ret = $plgin->process();
  return $ret;
}

Each plugin defines a class named PlginImpl, which works fine. But it should be possible to call further plugins specified within within the return value of process(). That would call the same method specified above, but fails with:

Fatal error: Cannot redeclare class PlginImpl in ..

Please note that each plugin is a class, i.e.:

class PlginImpl extends Plugin implements PluginInterface

Plugin offer some useful functions while PluginInterface defines i.e. process().

I assume that the fact that all plugins are named PlginImpl causes the problem, hence my question: is there a way to unload a class (PlginImpl) after loading it with require_once? Or is there an entirely different approach I should follow?


EDIT
I tried without succeeding the following things:

  • unset $plgin after process()
  • calling __destruct() – it doesn’t work neither within processPlugin() nor within the process method
  • 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-12T07:32:40+00:00Added an answer on May 12, 2026 at 7:32 am

    Since you can’t unload a class after you’ve loaded it, the only option you have is to rename each plugin.

    PluginX, PluginY, etc., but it shouldn’t matter as you can just force them to use the plugin interface as you showed.

    To load a specific plugin, you could simply have something like solomongaby suggests, but instead of a filename, you pass it the name of the plugin.. something like this:

    function loadPlugin($pluginName) {
        require_once $pluginName . '.php';
    
        $plugin = new $pluginName;
        //do whatever with $plugin
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 138k
  • Answers 138k
  • 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 The APIs you are looking for are in UIResponder: -… May 12, 2026 at 7:32 am
  • Editorial Team
    Editorial Team added an answer you should use BitmapData::getPixels and BitmapData::setPixels ... writing class instances… May 12, 2026 at 7:32 am
  • Editorial Team
    Editorial Team added an answer C-u 0 M-x byte-recompile-directory will compile all the .el files… May 12, 2026 at 7:32 am

Related Questions

Some background: As a personal project, I've been developing a kernel in c++. Things
I'm working with a legacy system that I'm experimenting with adding NHibernate to. I
I have a base class with an optional virtual function class Base { virtual
There are different ways of creating dynamic strings in C (with length that constantly
I'm using a bunch of different asp.net validation controls on a web form. Some

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.