Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:16200 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 27356 invoked by uid 1010); 10 May 2005 15:12:23 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 5279 invoked from network); 10 May 2005 14:55:45 -0000 Received: from unknown (HELO kmit.sk) (127.0.0.1) by localhost with SMTP; 10 May 2005 14:55:45 -0000 X-Host-Fingerprint: 195.28.69.139 mail.jobtion.com Linux 2.4 w/o timestamps Received: from ([195.28.69.139:55021] helo=sparky.datcon.sk) by pb1.pair.com (ecelerity 1.2 r(5656M)) with SMTP id BA/34-35155-07BC0824 for ; Tue, 10 May 2005 10:55:44 -0400 Received: from localhost (localhost [127.0.0.1]) by sparky.datcon.sk (Postfix) with ESMTP id B55771EA40 for ; Tue, 10 May 2005 16:55:40 +0200 (CEST) Received: from sparky.datcon.sk ([127.0.0.1]) by localhost (sparky [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 06639-01-7 for ; Tue, 10 May 2005 16:55:40 +0200 (CEST) Received: from [172.16.71.217] (adsl90.212-5-195.telecom.sk [212.5.195.90]) by sparky.datcon.sk (Postfix) with ESMTP id D22051EA39 for ; Tue, 10 May 2005 16:55:35 +0200 (CEST) Message-ID: <4280CB8B.4050101@kmit.sk> Date: Tue, 10 May 2005 16:56:11 +0200 User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.7) Gecko/20050503 X-Accept-Language: sk, en MIME-Version: 1.0 To: internals@lists.php.net References: <4qdcz84j.fsf@random.internal> <427FA67E.2020506@omniti.com> <427FC9D1.1030607@php.net> <4280AFD4.9080306@php.net> In-Reply-To: <4280AFD4.9080306@php.net> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: amavisd-new at datcon.sk Subject: Re: [PHP-DEV] Re: new overloading feature? From: ondrej@kmit.sk (=?UTF-8?B?T25kcmVqIEl2YW5pxI0=?=) 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)