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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:06:01+00:00 2026-05-24T05:06:01+00:00

maybe its late or something, but this is freaking me out. Basicly im writing

  • 0

maybe its late or something, but this is freaking me out. Basicly im writing framework for the excercise, trying to get my oop skill rolling, but im kinda stuck. I think i maybe hit a rookie err, that i just dont know of 🙂

So i have a bootstrap class which initializes the whole program. I creates a controller, in which you can call an app (or model if you prefer). All controllers and apps are sub classes of an initialization class, that implements the singleton pattern. This i because i would like to use the construct function for other init stuff based on the given controller/app.

Now the problem is, when i try to init an app from within the controller, the instance var is already set to the controller object (which i thought was null). If im not clear enough, here is the code in a very simplified and raw form:

<?php

final class Bootstrap {
    public function __construct() {
        $controller = Controller::init();
        $controller->index();
    }
}

abstract class Initialization {
    private static $_instance = NULL;

    final public static function init() {
        $c = get_called_class();

        var_dump(self::$_instance);

        self::$_instance = new $c();

        return self::$_instance;
    }

    final protected function app($app) {
        $app::init();
    }
}

final class Form extends Initialization { }

final class Controller extends Initialization {
    final public function Index() {
        $this->app('form');
    }
}

$bootstrap = new Bootstrap();

?>

The output is

null
object(Controller)[2]

Im confused why is the instance already set in the form app?? I thought it inherited it’s “own” static instance var??

  • 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-24T05:06:02+00:00Added an answer on May 24, 2026 at 5:06 am

    You only get your ‘own’ static instance var if you call it with late static binding, like static::$_instance instead of self::$_instance. Also, you would want to make it protected instead of private.

    self:: is determined at compile-time so to say, so will always reference Initialization::$_instance, regardless from which class extending it you call it. static:: is determined while the program runs.

    Code alterations:

    abstract class Initialization {
        protected static $_instance = NULL;
    
        final public static function init() {
            $c = get_called_class();
            static::$_instance = new $c();
            return static::$_instance;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is for a web application. And maybe it's a stupid question but
I know this may be a noob question, but it's bugging the heck out
Maybe the need to do this is a 'design smell' but thinking about another
Maybe this is a dumb question, but is there any way to convert a
Maybe I'm just thinking about this too hard, but I'm having a problem figuring
maybe its silly but I am not sure if there is difference between types
Very direct question, i need to know if its possible and maybe where to
Maybe it's just me, but I cannot understand the documentation regarding Junit test integration
Maybe I just don't know .NET well enough yet, but I have yet to
Maybe my understanding of agile development isn't as good as it should be, but

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.