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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:52:53+00:00 2026-06-12T02:52:53+00:00

This question may be obvious to some, but I am just beginning to scratch

  • 0

This question may be obvious to some, but I am just beginning to scratch the surface of multi-tier architecture with web applications, particularly with PHP. I have a library containing several objects and it is expanding quickly. I always try to think in terms of re-useability and break my projects down into small, reusable, and loosely coupled components so that I am not only creating the project but I am also creating the parts for future projects. I am trying to design a sort of package management system so that I can stop using the absolute paths within include statements for objects. I would like to have a single file containing includes to every class file within my library. Along with the includes, I want to add a class with a “singleton” pattern that will allow me to grab instances of every object that I have in the library on demand. I plan to create a static getter for each object that returns a reference to a new instance. Basically, something like this…

include('classa.php');
include('classb.php');
include('classc.php');
class pacman{
     private static $instance_stack;
     public static function GetPackage($strPackage){
         if(!self::$instance_stack){
             self::$instance_stack['classa']=new ClassA();
             self::$instance_stack['classb']=new ClassB();
             self::$instance_stack['classc']=new ClassC();
         }
         if(array_key_exists(strtolower($strPackage),self::$instance_stack)){
             return self::$instance_stack[strtolower($strPackage)];
         }
         else{
             return false;
         }
     }

}

Then if I want to get class a…

include('pacman.php');
$ClassA = pacman::GetPackage('classa');

I realize that this is a very rudimentary implementation. My example just covers the bare minimum. My problem isn’t implementing this; rather, it is a question of whether or not hundreds of uninstantiated classes from the includes will have a noticeable effect on performance. If so, does anyone know of a workaround? I can’t tell you how hard it is to keep track of the relative paths of hundreds of classes all sorted into directors by content.

  • 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-12T02:52:54+00:00Added an answer on June 12, 2026 at 2:52 am

    You should try autoloading them:

    <?php
    function __autoload($class_name) {
        include $class_name . '.php';
    }
    
    $obj  = new ClassA();
    $obj2 = new ClassB(); 
    ?>
    

    This loads classes “on-demand”, reducing the overhead and need to have all files included up-front. More information here: http://php.net/autoload

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

Sidebar

Related Questions

This may seem like an obvious question but we have a PHP/MySQL app that
This question may look familliar but I've discovered some rather more pertinent information and
The answer to this question may be painfully obvious but I can't find it
I am a newbie to C++, and this question may seem obvious to a
This question may seem blindingly obvious and I realise I am putting myself up
This question may seem trivial, but I hope you won't ignore it. Before destroying
This question may seem a little bit stackoverflow-implementation specific, but I have seen a
This question may have been asked before, but I had trouble finding an answer,
This one seems painfully obvious to me, but for some reason I can't get
This seems like an obvious question but there does not appear to be an

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.