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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:25:11+00:00 2026-05-26T22:25:11+00:00

I’m currently looking at creating an abstract class Building . I would then like

  • 0

I’m currently looking at creating an abstract class Building. I would then like multiple different types of a Building to inherit this abstract using properties from the database.

With inheritance I would usually have something like:

abstract class Building {
    protected
        $id,
        $name,
        $cost;

    public function getName() { // return name }

}
class CoffeeShop inherits Building {
    protected $id = 2, $name = 'Coffee Shop', $cost = '£15';
    public function sellCoffee() { // sell it }
}
class ConferenceCentre inherits Building {
    protected $id = 2, $name = 'Conference Centre', $cost = '£10';
    public function bookRoom() { // book it } 
}

Pretty standard, a standard blueprint building class that defines what the others should inherit and declare.
Let’s say there are over 100 different building types… some of them are pretty standard but all of their properties are defined in the database, allowing an admin to go in and change it’s name, costs, requirements etc and some of those may not need to define any special functionality but it would be cool to define that functionality if ever needed in the future.

Would it be possible to go into the database and fill/create an object with it’s properties and type without having to define the actual file first? If I was to actually create the file then it’s manual work and I’m tied to the file system rather than the actual buildings stored in the database.

Then I could do something like:

abstract class Building { // blah }

// Loop through DB to create objects that inherit the building class (factory?)
$building = new BuildingFactory('CoffeeShop');

// Random function that hints of the type (despite class file not existing)
public function (CoffeeShop $cs) { // Do stuff }

// Random test of type
if (gettype($building) == 'CoffeeShop') { // Do stuff }

I guess the question is… is there any way I can create classes without having to create the actual files. And I guess with the ability to check if that file actually exists and add custom functions if needed.

Otherwise I’d have to create 100+ files and have the factory pull them up and fill them in.

Thanks, Dominic

  • 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-26T22:25:12+00:00Added an answer on May 26, 2026 at 10:25 pm

    You can’t define a class without writing the definition. That’s true for any computer language, and that’s true for PHP as well.

    You can place the code into the database or generate the code based on data you fetch from your database however.

    But whenever you’re coming close to eval (which would be used for those), it’s most often more valuable to look if you’re asking the right questions when you create your design.

    It looks more to me that you have the same object all the time, but it only have some different data.

    And I’m not sure how many different functions those object(s) must have. You have not shared much information about the general structure of your application and the underlying domain logic, so it’s hard to tell within this first answer.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I would like to run a str_replace or preg_replace which looks for certain words
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I am currently running into a problem where an element is coming back from

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.