PHP singleton pattern – question about extends

phpsingleton

Just a quick question. I understand that Singleton patterns can be extended and that inheritance is applied. I was just wondering if I called a base class and then a extended class is there additional overhead than if I just called the extended class by itself?

Best Solution

If what you're talking about is something like

class BaseSingleton {
    public function DoSomething() {
    }
}

class ExtendedSingleton extends BaseSingleton {
    public function DoSomething() {
        parent::DoSomething();
    }
}

then yes, there is overhead in the call being forwarded from the child class's DoSomething() to the parent class's. If ExtendedSingleton does not redefine DoSomething(), though, there is no additional overhead.