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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:07:36+00:00 2026-06-13T02:07:36+00:00

I’m currently working on a project where we are developing an application that will

  • 0

I’m currently working on a project where we are developing an application that will be used to power content on multiple sites from a single set of files / hosting environment.

There are a number of PHP classes with names such as model_account and model_vehicle which are defined in seperate files named the save as the class name. We are using spl_autoload_register to load the class files as below (simplified):

function my_autoloader($class_name) {
    if(substr($class_name, 0, 6)=='model_') {
        require_once('models/'.$class_name.'.php');
    }
}

What we want to do, is if the visitor is accessing site xxx and we create an instance of a class, eg $account = new model_account(); – actually create an instance of class model_xxx_account if the file exists (models/model_xxx_account.php), but if it doesn’t, just include the models/model_account.php file and create an instance of model_account.

Likewise, if a visitor came from site yyy, we would want to use model_yyy_account if exists, but full back to model_account if it doesn’t.

Essentially what we wish to do is create an instance of a different class if conditions are met, but from the same instantiation call.

We’re not using an off-the-shelf framework like CI or Cake. Also, I’ve slightly simplified the naming conventions for this post. Sorry if my OO terminology isn’t spot on.

  • 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-13T02:07:38+00:00Added an answer on June 13, 2026 at 2:07 am

    It actually sounds like you should be using some sort of factory pattern to deal with your class loading.

    If you do $account = new SomeClass(), it does not make any sense to ever really end up with an object of class Bumblebee.

    You should technically have some sort of account factory that decides which class to give you.

    You code will end up looking more like $account = AccountFactory::retrieveModel(), which then can determine which model you want to load WITHOUT delegating to your autoloader.

    The point of the autoloader is to essentially say “I want THIS exact class”, and isn’t to be wibbly wobbly or in particular be making any sort of decisions of that sort. Your factory can actually go through your file structure and determine which class to pass back in the function call, and in your code you aren’t relying on new to get the model you want, since it seems in theory all of your account models will be sharing the same interface or at least extending model_account.

    AccountFactory can essentially say, “model_yyy_account exists, thus return new model().

    • 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 ’ in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
I need a function that will clean a strings' special characters. I do NOT
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
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
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.