I am trying to extend the PDO class as well as turn it into a singleton. The only problem is that PDO’s constructor is public, and PHP will not let me override it as a protected method. Is there any imaginative way around this? Will I be stuck with that loose end forever if I attempt this? An alternative may be not to extend PDO, but rather hold it in a static property, and do operations with it, but I wanted my class to retain all of the functionality of PDO if possible.
Share
You can just wrap the PDO class in your own “Singleton Factory” object. Basically, you implement your own singleton that contains a (single) PDO instance. (Note that I don’t know PHP syntax so this is Java, but you should be able to get the idea)
A more verbose explaination can be found here: http://www.wikijava.org/wiki/Singleton_Factory_patterns_example
(Again, Java … sorry – but I believe it’ll get you where you where you want to go)