Paste Description for suv4x4
Solution for extensible singleton
- suv4x4
- Wednesday, June 28th, 2006 at 2:44:03am MDT
- class Super
- {
- function Func()
- {
- echo "Super Func<br>";
- $this->Func2();
- }
- function Func2()
- {
- echo "Super Func 2<br>";
- }
- // singleton
- static private $instances = array(); // assoc array with one single instance for every class
- static protected function getInstance($c=__CLASS__) // overload in subclasses (as public)
- {
- if(is_null(self::$instance[$c])) {
- self::$instance[$c] = new $c();
- }
- return self::$instance[$c];
- }
- }
- class Sub extends Super
- {
- function Func()
- {
- echo "Sub Func<br>";
- parent::Func();
- }
- static public function getInstance($c=__CLASS__)
- {
- return parent::getInstance($c);
- }
- function Func2()
- {
- echo "Sub Func 2<br>";
- parent::Func2();
- }
- }
advertising
Update the Post
Either update this post and resubmit it with changes, or make a new post.
You may also comment on this post.
Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.