Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:21104 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 86890 invoked by uid 1010); 8 Dec 2005 04:16:04 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 86875 invoked from network); 8 Dec 2005 04:16:04 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Dec 2005 04:16:04 -0000 X-Host-Fingerprint: 17.250.248.46 smtpout.mac.com FreeBSD 4.7-5.2 (or MacOS X 10.2-10.3) (1) Received: from ([17.250.248.46:52447] helo=smtpout.mac.com) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id DA/0B-14828-283B7934 for ; Wed, 07 Dec 2005 23:16:03 -0500 Received: from mac.com (smtpin08-en2 [10.13.10.153]) by smtpout.mac.com (Xserve/8.12.11/smtpout10/MantshX 4.0) with ESMTP id jB84Fxoi018943 for ; Wed, 7 Dec 2005 20:15:59 -0800 (PST) Received: from [10.0.1.102] (c-24-98-128-251.hsd1.ga.comcast.net [24.98.128.251]) (authenticated bits=0) by mac.com (Xserve/smtpin08/MantshX 4.0) with ESMTP id jB84FvAE023945 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=NO) for ; Wed, 7 Dec 2005 20:15:58 -0800 (PST) Mime-Version: 1.0 (Apple Message framework v746.2) In-Reply-To: <43970D54.1040206@zend.com> References: <43970D54.1040206@zend.com> Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-ID: <63053C31-56D1-49A3-8D24-4FC41188A92A@mac.com> Content-Transfer-Encoding: 7bit Date: Wed, 7 Dec 2005 23:15:55 -0500 To: internals@lists.php.net X-Mailer: Apple Mail (2.746.2) Subject: Re: [PHP-DEV] $this->this and avoiding circular references From: apinstein@mac.com (Alan Pinstein) My question is closely related to the one discussed on this php-dev thread: http://thread.gmane.org/gmane.comp.php.devel/32430 Someone just sent me this link, which I didn't find myself when searching b/c the searches strip "this" from queries. Anyway, the question is related to reference counting of objects when assigned by value and by reference. It is a very important OO topic as the ability to have a non-ref-counted object "handle" is basically requisite to prevent circular reference deadlocks in OO projects. If the way I have proposed doesn't work, then what is the official way? And there *must* be one, otherwise, there is no way to avoid huge memory leaks (deferred release until end-of-script, I know, but it's a memory leak in the context of the script while it's running) with this kind of OO arrangement. In particular what confuses me is, why does, at least on PHP 5.0.4, this: $obj = &$this->this; // doesn't seem to increment the refcount of the object behaves differently from: $obj = &$this; // does seem to increment the refcount to the object References to $this should not only be valid, but are pretty much required for proper memory management in an OO environment, unless there is some other sanctioned way to get a weak reference... now I am not sure if the fact that making a & reference to an object doesn't increment the refcount is intended behavior, or an unintended side effect that may change. This is one of my major questions. Also, in regards to the thread linked above, I'd say that making & $this an error is not desirable behavior; but maybe changing the value of $this should be (ie in C terms, $this is not an lvalue). Although, in C++/Obj-C you *can* even change this/self... in fact it's common in Obj-C: - (id) init { if (self = [super init]) { /* etc */ } return self; } Of course PHP is not Obj-C, but it's OO and garbage collected in a similar way, so PHP has the same need for manipulating $this; that is, creating weak references. Alan On Dec 7, 2005, at 11:27 AM, Antony Dovgal wrote: > On 07.12.2005 18:40, Alan Pinstein wrote: >> Hi all- > > > Please use php-general@lists.php.net for questions regarding > development *in* PHP. > -- > Wbr, Antony Dovgal