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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:08:56+00:00 2026-05-20T11:08:56+00:00

Scenario The system has classes declared in /system/classes/ . The application has classes declared

  • 0

Scenario
The system has classes declared in /system/classes/.
The application has classes declared in /application/classes/.

If there is class in the application folder that has the same name as a class in the system folder then the class in the application folder should extend the class in the system folder.

Not all classes in the system folder will be overwritten by a class in the application folder.

Question
How can you cause the class in the system folder to extend the class in the application class only if there is a class in the application folder.

NB: All classes that can be overwritten are static classes
NB: Even if we have to name the application classes my_className it is fine, as long as we can still just call className::functionName()

I guess Im looking for something similar to how Code Igniter does it.


Edit

Example Class
The below class is used as a loader to load in all other classes (be they libraries, processes or other). It is also used to load in css/image/js files ect.

If the user was to extend the class they might want to add an ini() function which would be used to load in ini files.

class load {

    protected static $helpers;
    protected static $configs;
    protected static $libraries;
    protected static $processes;
    protected static $js;
    protected static $css;

    public static function init() {
        self::$helpers = new stdClass();
        self::$libraries = new stdClass();
        self::$configs = new stdClass();
        self::$processes = new stdClass();
        self::$css = new stdClass();
        self::$js = new stdClass();
    }

    public static function config($name) {
        if (isset(self::$configs->$name) && is_object(self::$configs->$name))
            return self::$configs->$name;

        if (is_file(CONFIG_DIR . $name . '.php')) {
            require_once(CONFIG_DIR . $name . '.php');
            self::$configs->$name = new $name();
            return self::$configs->$name;
        }
        throw new exception('Could not load config file \'' . $name . '\'');
        return false;
    }

    public static function helper($name) {
        if (isset(self::$helpers->$name) && is_object(self::$helpers->$name))
            return self::$helpers->$name;

        if (is_file(APP_HELPER_DIR . $name . '.php')) {
            require_once(APP_HELPER_DIR . $name . '.php');
            self::$helpers->$name = new $name();
            return self::$helpers->$name;
        }

        if (is_file(HELPER_DIR . $name . '.php')) {
            require_once(HELPER_DIR . $name . '.php');
            self::$helpers->$name = new $name();
            return self::$helpers->$name;
        }
        throw new exception('Could not load helper file \'' . $name . '\'');
        return false;
    }

    public static function library($name, $params = array()) {
        if (empty($params) && isset(self::$libraries->$name) && is_object(self::$libraries->$name))
            return self::$libraries->$name;

        if (is_file(APP_LIBRARY_DIR . $name . '.php')) {
            require_once(APP_LIBRARY_DIR . $name . '.php');
            self::$libraries->$name = new $name($params);
            return self::$libraries->$name;
        }

        if (is_file(LIBRARY_DIR . $name . '.php')) {
            require_once(LIBRARY_DIR . $name . '.php');
            self::$libraries->$name = new $name();
            return self::$libraries->$name;
        }
        throw new exception('Could not load library file \'' . $name . '\'');
        return false;
    }

    public static function process($name, $args = array()) {
        if (isset(self::$processes->$name) && is_object(self::$processes->$name))
            return self::$processes->$name;

        if (is_file(PROCESS_DIR . $name . '.php')) {
            require_once(PROCESS_DIR . $name . '.php');
            if (empty($args)) {
                self::$processes->$name = new $name();
                return self::$processes->$name;
            } else {
                self::$processes->$name = new ReflectionClass($name);
                return self::$processes->$name->newInstanceArgs($args);
            }
        }
        throw new exception('Could not load process file \'' . $name . '\'');
        return false;
    }

    public static function css($name) {
        if (isset(self::$css->$name) && !empty(self::$css->$name))
            return self::$css->$name;

        self::$css->$name = '<link rel="stylesheet" type="text/css" href="' . CSS_PATH . $name . '.css">';
        return self::$css->$name;
    }

    public static function js($name) {
        if (isset(self::$js->$name))
            return self::$js->$name;

        self::$js->$name = '<script src="' . JS_PATH . $name . '.js"></script>';
        return self::$js->$name;
    }

    public static function template($name, $vars = array()) {
        if (is_file(TEMPLATE_DIR . $name . '.php')) {
            ob_start();
            if (!empty($vars))
                extract($vars);
            require(TEMPLATE_DIR . $name . '.php');
            $contents = ob_get_contents();
            ob_end_clean();
            return $contents;
        }
        throw new exception('Could not load template file \'' . $name . '\'');
        return false;
    }

}
  • 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-20T11:08:57+00:00Added an answer on May 20, 2026 at 11:08 am

    As far as I know code Igniter do replace classes, rather than extending them.

    The more pratical way is to dinamically generate the code:

    $code = file_get_contents($appFile);
    if ( file_exists( $systemFile ) )
    {
        //don't do this ! Just a proof of concept, use regexp or code tokenizer
        //you will also need to programmatically determine MyClass and SystemClass
        $code = str_replace ('class myClass', 'class MyClass extends SystemClass', $code);
    }
    eval ($code)
    

    Please note that eval is generally considered evil for good reasons, so be sure to double check your code.
    You may want to re-think your framework design instead.

    UPDATE: if classes are just statical you may want to look into the Decorator pattern and __call() __get() __set(). That may suffice and avoid the eval() route.

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

Sidebar

Related Questions

The scenario: we have a web system that automatically generates office 2003 excel files
Scenario: You have an ASP.Net webpage that should display the next image in a
The following F# code declares base and descendant classes. The base class has a
FilenameFilter has an accept method that I can implement to tell system how I
Here is my scenario: I'm building a web application for an embedded system user
Scenario: I have an application that pulls data from a SQL database as well
Given a scenario: I have my own system's object structure. Now there are more
I have the following winforms classes: class EntityEditorForm<T>: System.Windows.Forms.Form where T: ICloneable<T> {} class
Consider that my system has memory, but it is scattered in different places (fragmented).
I have a Windows application based on Java, that I should like to install

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.