Re: Re: new overloading feature?

From: Date: Tue, 10 May 2005 14:56:11 +0000
Subject: Re: Re: new overloading feature?
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-16200@lists.php.net to get a copy of this message
Lukas Smith wrote: > So please explain to me how you would write a singleton static method > for a base class from which you can inherite. Suddenly the idea with > using the class name becomes less useful. IMHO, you need singleton factory :) Inheritance is very strong relationship between classes. For example I have base class 'Animal' and derived classes 'Dog' and 'Cat'. I can find similarity between 'Dog' and 'Cat'. (They are animals) If I have base class Singleton and derived classes 'MyCar' and 'MyCat'. I can't find similarity between this classes. Solutions is: class SingletonFactory { private $instances; __construct() { $this->instances = array(); } function getInstance($name) { if(is_a($this->instances[$name], $name) === false) { $this->instances[$name] = new $name; } return $this->instances[$name]; } } FYI: SingletonFactory can be a pure static class. -- Ondrej Ivanic (ondrej@kmit.sk)

« previous php.internals (#16200) next »