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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:34:11+00:00 2026-06-01T08:34:11+00:00

I’m expanding my php and general coding knowledge by writing my own ‘simple’ CMS

  • 0

I’m expanding my php and general coding knowledge by writing my own ‘simple’ CMS system.

My database structure follows:

USERS --< WEBSITES --< PAGES

In my logic, I have three classes, a User, Website and Page class. NOT INHERITED

The User class has all the attributes from the USER TABLE plus a $_website attribute,

The Website class has all the attributes of the WEBSITE TABLE plus an ARRAY of Page objects

The way I have decided to work this is, on page load, these classes will be created and filled with the database data.

So then in the html I can echo out results simply by calling the class like so:

$USER -> name;
$USER -> website -> get_pages();
$USER -> website -> pages[0] -> get_header();

I Realised that these classes could be inherited, so Page inherits Website and Website inherits User

But if I do it that way, then I’ll instantiate the Page class like:

$PAGES = array(); 
$PAGES[] = new Page( $constructor_data_to_construct_user_website_and_page );

Now IF I do it this way, the object $PAGES[0] will have all the info to do with that page, and all the info to do with the Website (first parent),
and all the info to do with the User ( second parent )

If i then create another Page, i’m just copying the same User and Website details Yes?

So if i were to var_dump $PAGES[0] id get ALL the info to do with USER, WEBSITE and PAGE

If i were to var_dump $PAGES[1] id get ALL THE SAME information for USERS AND WEBSITE, but just the different Page data.

So inheritance, is causing unnecessary copying of the User and Website objects

Because I could essentially do:

$PAGES[0] -> username // username is a property of the Users class
$PAGES[1] -> username

both would return EXACTLY the same value.

surely this is bad because data is being unnecessarily copied!

Is This Correct?

Or is this question a load of rubbish and this isn’t the kind of situation inheritance is used?

  • 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-01T08:34:12+00:00Added an answer on June 1, 2026 at 8:34 am

    This is exactly the sort of situation where you must not use inheritance.

    Inheritance is meant to model an IS-A relationship. Typical example: a Student is a type of Person, so Student inherits from Person.

    Inheritance is not, not, NOT meant to model a HAS-A relationship. Typical example: a Car has an Engine, but Car is not a type of Engine.

    When we have a HAS-A relationship (e.g. a User has Website) you should almost in all cases use composition instead of inheritance:

    Bad

    class Website extends User {}
    

    Good

    class Website {
        private $users;
    }
    
    • 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&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.