i found something interesting the other day using PHP. let's say you have a base class (which would be using the singleton design pattern) with a static data member called $instance. later, you inherit the base class with another two additional classes and have them utilize the $instance data member (say through setting it in a method called getInstance()). originally, i had thought that each instantiating class would get its own copy of $instance. nope!!! because the data member is static in the base class, it really only pertains to the base class, especially when you start referring to it as self::$instance.
i'm not sure if this is a good explanation of the situation, but i learned a truly valuable lesson today: be careful when using static data members and inheritance. If you intend to do some sort of polymorphism with the static data member, it probably won't behave as you'd expect.
Trackbacks: (Trackback URL)
