Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:13751 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 90307 invoked by uid 1010); 6 Nov 2004 04:58:32 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 90244 invoked from network); 6 Nov 2004 04:58:31 -0000 Received: from unknown (HELO rproxy.gmail.com) (64.233.170.198) by pb1.pair.com with SMTP; 6 Nov 2004 04:58:31 -0000 Received: by rproxy.gmail.com with SMTP id q1so144185rnf for ; Fri, 05 Nov 2004 20:58:31 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:references; b=HHAN15iOqyAFcu7o+Gsk/5eI6IW/HbePnmtto9FucONLkKTrX7/a58lYWPMupGOQKJRuRZtmuhZBYbrrXsn+fBJKzyxiQ1yKeUUb7+PEydCaE5W/1iTyssZ/CkFjVyVzKxMvTCixYN4DVPis2sUEZIwi5caylNOcMmLMgd8Pj1s= Received: by 10.38.209.1 with SMTP id h1mr761416rng; Fri, 05 Nov 2004 20:58:31 -0800 (PST) Received: by 10.38.78.22 with HTTP; Fri, 5 Nov 2004 20:58:31 -0800 (PST) Message-ID: <5630944604110520582c85b146@mail.gmail.com> Date: Sat, 6 Nov 2004 05:58:31 +0100 Reply-To: Douglas Livingstone To: internals@lists.php.net In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: <1135.216.98.60.147.1099702310.squirrel@216.98.60.147> Subject: Re: [PHP-DEV] new overloading feature? From: rampant@gmail.com (Douglas Livingstone) > but will be glad to discuss the merits of this and > its implementation if any one else feels it could be a useful feature. Hi Derrell, Below is some code I wrote to do something very similar to this from an external perspective. It basically replaces the use of $this with a reference to the class's own getInstance() method. The getInstance is not used in code which calls the class, so the fact that it is all running off the same instance is not visible from outside. I'm not sure what the memory usage looks like if you do things like this. I think the key would be to put __constructor code in the getInstance mathod instead. A clean way to do this internally would be nice. A way to redefine $this may be better than a __new() method. Some sort of method_preview would be good enough for the code belown (where $this would be set to self::instance()). class StaticClass { //// Statics Code //// static protected $instance = false; protected function instance() { if(!self::$instance) { self::$instance = new self; } return self::$instance; } //// Class Code //// protected $value; function set_value($value) { $t = self::instance(); // Call this whenever you want a private variable $t->value = $value; } function get_value() { $t = self::instance(); return $t->value; } } Regards, Douglas