Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:21095 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 39751 invoked by uid 1010); 8 Dec 2005 02:28:01 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 39736 invoked from network); 8 Dec 2005 02:28:01 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Dec 2005 02:28:01 -0000 X-Host-Fingerprint: 17.250.248.89 smtpout.mac.com FreeBSD 4.8-5.1 (or MacOS X 10.2-10.3) Received: from ([17.250.248.89:55501] helo=smtpout.mac.com) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 82/05-14828-03A97934 for ; Wed, 07 Dec 2005 21:28:00 -0500 Received: from mac.com (smtpin04-en2 [10.13.10.149]) by smtpout.mac.com (Xserve/8.12.11/smtpout02/MantshX 4.0) with ESMTP id jB82RuZs008694 for ; Wed, 7 Dec 2005 18:27:56 -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/smtpin04/MantshX 4.0) with ESMTP id jB82RsmQ019202 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=NO) for ; Wed, 7 Dec 2005 18:27:56 -0800 (PST) Mime-Version: 1.0 (Apple Message framework v746.2) In-Reply-To: <439709DB.9090503@iamjochem.com> References: <439709DB.9090503@iamjochem.com> Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-ID: <8616B99B-E809-4FCC-B1CD-11F5BBEE24AC@mac.com> Content-Transfer-Encoding: 7bit Date: Wed, 7 Dec 2005 21:27:52 -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) > are you using ph4 or php5? PHP5 > are you setting $this->this yourself or 'is it just there'? No, I'm not setting it, just reading it (see addChildObject() code below), if that's what you mean. -Alan > > Alan Pinstein wrote: >> Hi all- >> I've been trying to avoid circular references in some data import >> scripts and finally figured out how to do it. However, I wanted >> to ask you guys to make sure that what I'm doing is something >> that's legit and can be relied on into the future. >> Also, please note that I tried searching the archives for "this" >> and "this->this" but the searcher keeps removing "this" from my >> query! So sorry if this is asked and answered.... >> So, my objects are in a parent-child relationship and they both >> have links to each other... pretty standard circular reference >> scenario: >>> ParentObject: >>> >>> function addChildObject($c) >>> { >>> $this->children[] = $c; >>> $c->setParent($this->this); // this syntax is the only >>> way > > assuming php4, I would say this these lines should be (difficult > to tell though, without more insight/code/brains to play with ;-): > > function addChildObject(&$c) { > $this->children[] =& $c; > $c->setParent( $this ); > } > >>> I found to make "$this" not get refcounted here >>> } >>> >>> Now, to make this work as it should without incrementing the ref >>> counts when storing the link to the parent, setParent() needs to >>> have a non-refcounted pointer to the object: >>> >>> ChildObject: >>> >>> // need & in both places to make the ref not get ref-counted >>> function setParent(&$parent) >>> { >>> $this->-parent = &$parent; >>> } >> My question is, is "$this->this" valid syntax? Can it be relied >> on? Is my overall approach sane? >> It's very important that I get memory management working in such >> a way here because the objects are used in large loops for >> importing data, and without this, the script uses unbounded >> amounts of memory. With this, it uses a finite amount of memory >> and works beautifully. >> Thanks in advance, >> Alan >