Class inheritance in PHP with Singleton Pattern only works if the instance variable in the inherited class is reinitialized. But why?
问题 I have a main class with the singleton function instance() and the associated variable $instance . Now I create several subclasses and let the main class inherit. I do not re-define the singleton function and variable, because of the useful inheritance. Unfortunately, each instance points to the 1st subclass. Only when in the subclasses the $instance variable is initialized to null it works, but why? With the keywords static and not self , the scope should remain in the subclass. Here is the