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

  • Home
  • SEARCH
  • 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 9134137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:36:27+00:00 2026-06-17T08:36:27+00:00

This should be easy.. can someone explain the syntax for me? I have a

  • 0

This should be easy.. can someone explain the syntax for me?

I have a controller which instantiates a bootstrap class (new keyword) which instantiates the config class.

the controller then instantiates a startpage class which extends the bootstrap class. In the startpage class I’m trying to access the config object in the bootstrap (parent) class.

Can this even be done? Or does startpage have to instantiate bootstrap directly? Does instantiating startpage that extends bootstrap, overwrite bootstrap? or is my syntax just wrong?

Controller (index page)

try {
    if (!include($paths['root'] . $paths['framework'] . '/core/AutoLoader.php')) {
        throw new Exception ('<b>Error - AutoLoader is missing</b>');
    }
    $loader   = new AutoLoader($paths);
    $appStack = new BootStrap($paths);
    $app      = new StartPage();
    $app->start();
} catch (Exception $e) {
    echo
        '<p><b>EXCEPTION</b><br />Message: '
        . $e->getMessage()
        . '<br />File: '
        . $e->getFile()
        . '<br />Line: '
        . $e->getLine()
        . '</p>';
}

Bootstrap class:

class BootStrap {
    protected $config;

    /**
     * --------------------------------------------------------------------------
     ** GETTERS
     * --------------------------------------------------------------------------
     *
     */
    public function getConfig() { return $this->config; }

    /**
     * --------------------------------------------------------------------------
     * __construct()
     * PUBLIC method
     * = Starts a new session, loads stylesheets, loads classes
     * --------------------------------------------------------------------------
     *
     */
    public function __construct($paths) {

        /**
         * --------------------------------------------------------------------------
         * load Config class
         * --------------------------------------------------------------------------
         *
         */
        try {
            if (!class_exists('Config')) {
                throw new Exception ('<b>Error - Configuration class is missing</b>');
            }
            $this->config      = new Config();
        } catch (Exception $e) {
            echo
                '<p><b>EXCEPTION</b><br />Message: '
                . $e->getMessage()
                . '<br />File: '
                . $e->getFile()
                . '<br />Line: '
                . $e->getLine()
                . '</p>';
        }
    }
}

Startpage class:

class StartPage extends BootStrap {

    /**
     * --------------------------------------------------------------------------
     * __construct()
     * PUBLIC method
     * = Starts a new session, loads stylesheets, loads classes
     * --------------------------------------------------------------------------
     *
     */
    public function __construct() {
    }

    /**
     * --------------------------------------------------------------------------
     * Start()
     * PUBLIC method
     * = loads the web page
     * --------------------------------------------------------------------------
     *
     */
    public function Start() {

        // path to includes
        $inc_path = $this->paths['root'] . $this->paths['medium'];

        // instantiate page, html header
        $charset     = $this->config->getCharset();
        $title       = $this->config->getTitle();
        $description = $this->config->getDescription();
    }
}
  • 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-17T08:36:28+00:00Added an answer on June 17, 2026 at 8:36 am

    As soon as you give StartPage its own __construct() method, you effectively “hide” the one in Bootstrap, over-riding it completely. So $foo = new StartPage() only runs the __construct() code from the StartPage class.

    In order to also run the __construct() code in the Bootstrap parent class, you have to add an explicit call to it, using parent::__construct().

    In case you wonder why PHP doesn’t do this for you, here are three things you couldn’t do if it were automatic:

    1. Run code both before and after the parent constructor, by choosing when to call parent::__construct().
    2. Replace the entire constructor logic with something else while still inheriting the rest of the class.
    3. Pass values into the parent constructor which are always the same / can be chosen automatically by the child class, but which would need to be provided explicitly to the parent class.

    EDIT: To summarise the further clarifications below, creating a particular instance of the parent (Bootstrap) class will not make any difference to later creations of other instances of the same class or its child class (StartPage); each is a separate object and will call __construct independently.

    If you want multiple StartPage objects to refer to one particular instance of the Bootstrap class, then inheritance is not the right mechanism. Instead, you will need to pass the created Bootstrap instance into each StartPage instance via some form of Dependency Injection.

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

Sidebar

Related Questions

This should be easy for someone, I just can't seem to get the syntax
I'm new to JSON, but I have experience in PHP. Can someone explain to
So this should be pretty easy, yet I can't get it work. I have
Ok this should be easy but I can NOT figure it out. I have
This should be easy to find out but I can't seem to find it
This one should be easy. I just can't figure out what to search for...
So this should be a real easy question but I can't seem to find
This seems like it should be easy, but I can't quite find an explanation
This should be quite easy, and I have done some research on this. I
This seems like it should be easy as pie, but I can't seem to

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.