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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:50:21+00:00 2026-06-16T00:50:21+00:00

In my project I’m processing data and working with the results. There is an

  • 0

In my project I’m processing data and working with the results. There is an abstract class which looks like the following:

class AbstractInterpreter
{
    public function interprete( $data )
    {
        throw new Exception('Abstract Parent, nothing implemented here');
    }
}

And then there are various different implementations of the AbstractInterpreter:

class FooInterpreter extends AbstractInterpreter
{
    public function interprete( $data )
    {
        return "resultFoo";
    }
}
class BarInterpreter extends AbstractInterpreter
{
    public function interprete( $data )
    {
        return "resultBar";
    }
}

My calling code creates the interpreters and collects the results:

//this is the data we're working with
$data = "AnyData";

//create the interpreters
$interpreters = array();
$foo = new FooInterpreter();
$bar = new BarInterpreter();
$interpreters[] = $foo;
$interpreters[] = $bar;

//collect the results
$results = array();
foreach ($interpreters as $currentInterpreter)
{
    $results[] = $currentInterpreter->interprete($data);
}

I’m currently creating more and more interpreters and the code gets messy… For each interpreter I need to add a certain include_once(..) and I have to instantiate it and put it into the $interpreters.

Now, to finally ask my question:
Is it possible to automatically include and instantiate all interpreters that are in a specific directory and put them into the $interpreters?

In other languages this would be some kind of a plugin-concept:
I create different implementations of AbstractInterpreter, put them in a specific subdirectory and the software uses them automatically. I would not have to modify the code which loads the interpreters as soon as it is finished.

  • 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-16T00:50:23+00:00Added an answer on June 16, 2026 at 12:50 am

    I don’t know if it’s possible automatically, but you can write a few lines code to get the same result.

    function includeInterpreters($path) {
    
        $interpreters=array();
    
        if ($dh = opendir($path)) {
            while (($file = readdir($dh)) !== false) {
    
                include_once($path.$file);
                $fileNameParts=explode('.', $file);
                $interpreters[]=new $fileNameParts[0];
    
            }
            closedir($dh);
        }
    
        return $interpreters;
    }
    
    $interpreters= includeInterpreters('/path/plugins');
    

    Name your class files as InterpreterName.php and put into the same directory, for example plugings

    And yes, this looks messy.

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

Sidebar

Related Questions

Project Silk looks good for social networking applications where there are streams of frequently
Project I've developed a remoting class which is used to replace a subset of
My project.clj file looks like this (defproject cljs-template 0.1.0-SNAPSHOT :description FIXME: write this! :url
The project that I am working on (Node.js) implies lots of operations with the
Project CompetitionServer.exe raised exception class ESQLiteException with message 'Error executing SQL. Error [1]: SQL
Project I'm working on uses jQuery. I have a series of Ajax calls being
project is written on php. There is timestamp field in mysql it updates automatically.
Project A contains a WPF Window (Data Entry Form) with a stack panel of
our project uses HttpRuntime.Cache.Get and HttpRuntime.Cache.Insert for storing and retrieving data from the cache.
Project file here if you want to download: http://files.me.com/knyck2/918odc So I am working on

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.