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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:37:18+00:00 2026-06-11T19:37:18+00:00

I’ve created a plugins system, and I’ve created everything in that system except, how

  • 0

I’ve created a plugins system, and I’ve created everything in that system except, how can I inclusion plugins files to execute it.

I’m tried to create a method, Which is doing include plugins files to execute it.

— Firstly — :
The method that get all plugins files, and that begin with index word which indicates the main file of plugin (i.g. index-pluginName.php), and add the path and file name to an array.

public function getPluginFiles($plugin_folder) {
  $dir = opendir($plugin_folder);
  while ($files = readdir($dir)) {
     if ($files == '.' || $files == '..')
        continue;

     if (is_dir($plugin_folder.'/'.$files))
        $this->getPluginFiles($plugin_folder.'/'.$files);


     if (preg_match('/^[index]+/i', $files)) {
        $this->plugins_path[$plugin_folder.'/'.$files] = $files;
     }
  }
  closedir($dir);       
}

— secondly — :
The method that include all the main file of plugins to execute, and this method get the path and name of plugin file from the array that created earlier .

public function includePlugFiles() {
   $this->getPluginFiles($this->plugin_folder);
   foreach ($this->plugins_path as $dir=>$file) {
     include_once (dirname($dir)."/".$file);
   }
}

Also see an example of code that exists in plugin file:

function test() {
    echo " This is first plugin <br/>";
}

$plugin->addHook('top', test); // parameters(top=position, test=callback)

Now, when I create an instance of the object to be this form .

$plugin = new plugin;
$plugin->includePlugFiles();

But after all this, shows error message

Fatal error: Call to a member function addHook() on a non-object in .... projects\plugins\index-test.php on line 7

This is the code of line 7:

$plugin->addHook('top', test); // parameters(top=position, test=callback)

I know the problem occur because, the object will not be created.
and the problem is can’t create the object in every main plugin file.

  • 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-06-11T19:37:19+00:00Added an answer on June 11, 2026 at 7:37 pm

    It’s probably not the cleanest solution, but instead of trying to reference the $plugin symbol (which is outside the scope of the plugin file), you could also do this:

    $this->addHook('top', test);
    

    Alternatively, you could explicitly create the reference inside the includePlugFiles() method:

    public function includePlugFiles()
    {
         $plugin = $this;
    
         $this->getPluginFiles($this->plugin_folder);
         foreach ($this->plugins_path as $dir=>$file) {
             include_once (dirname($dir)."/".$file);
         }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't

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.