Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:26887 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 70121 invoked by uid 1010); 10 Dec 2006 16:18:34 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 70106 invoked from network); 10 Dec 2006 16:18:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Dec 2006 16:18:34 -0000 Authentication-Results: pb1.pair.com header.from=pollita@php.net; sender-id=unknown; domainkeys=good Authentication-Results: pb1.pair.com smtp.mail=pollita@php.net; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain php.net from 140.211.166.39 cause and error) DomainKey-Status: good X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: pollita@php.net X-Host-Fingerprint: 140.211.166.39 osu1.php.net Linux 2.4/2.6 Received: from [140.211.166.39] ([140.211.166.39:46046] helo=osu1.php.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9B/D6-00543-4133C754 for ; Sun, 10 Dec 2006 11:17:59 -0500 X-DomainKeys: Ecelerity dk_sign implementing draft-delany-domainkeys-base-01 DomainKey-Signature: q=dns; a=rsa-sha1; c=nofws; s=mx; d=php.net; h=From:Subject:To:Date; b=Mvib0sHh+Mhi+TkxxcRW91dEwJZaWcfcOjC4Xxs1QbfPV7KxU1LHG3uTZTXi60fU nuHoF4noQcXdAiMkZi9CqQG0bmVGk4yLUDZ/ruKZPZLD0iwxdN98HTr6YITPF14c Authentication-Results: osu1.php.net smtp.user=pollita; auth=pass (LOGIN) X-Host-Fingerprint: 69.181.128.213 unknown Received: from [69.181.128.213] ([69.181.128.213:3297] helo=[192.168.1.102]) by osu1.php.net (ecelerity 2.1.1.11-rc1 r(13363/13364M)) with ESMTPSA (cipher=AES256-SHA) id 4E/00-08741-1343C754 for ; Sun, 10 Dec 2006 08:22:09 -0800 Message-ID: <457C330C.5050506@php.net> Date: Sun, 10 Dec 2006 08:17:16 -0800 User-Agent: Thunderbird 1.5.0.8 (Windows/20061025) MIME-Version: 1.0 To: Sebastian Bergmann CC: internals@lists.php.net References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [RFC] Magic Method that handles unset($object) From: pollita@php.net (Sara Golemon) > A possible solution to this problem would be the introduction of yet > another "magic" method. This method would be automatically called when > unset() is called on an object that implements it. Unfortunately, the > name __unset() is already taken. > > Is there another solution to this problem (apart from explicitly > unsetting the $children array on the $parent object)?And even if there > is I think that this method would be usefull. > To do this >right< you'd need notification, not just that unset() was called on the object, but what the current state of *both* of its relevant reference counts are. class foo { public function __delref($objectstore_refcount, $zval_refcount) { if ($objectstore_refcount == 1) { /* Only one zval is pointing to this object, * e.g. the one used/shared by the child's backreference */ if ($zval_refcount == 1) { /* Only one variable is pointing to this zval, * the child's backreference property */ $this->children = array(); } } } } Of course, that assumes you only have one child. Once you introduce multiple children, they'll *probably share one object store reference through a common zval with multiple references, so you *could* do: class foo { public function __delref($objectstore_refcount, $zval_refcount) { if ($objectstore_refcount == 1) { /* Only one zval is pointing to this object, * e.g. the one used/shared by the child's backreference */ if ($zval_refcount == count($this->children)) { /* Only one children's properties are pointing to this zval */ $this->children = array(); } } } } But that doesn't cover the (quite common) case where there are multiple object store references spread out among the children (and possibly other variables not contained in the object itself). Unfortunately you *can't* aggregate the total number of variable->zval->object references ince at this point in runtime, only the zval being dereferenced is known for certain. By the way, this is part of the reason why PHP doesn't have delete(). -Sara