Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:27592 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 35129 invoked by uid 1010); 22 Jan 2007 21:04:09 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 35114 invoked from network); 22 Jan 2007 21:04:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Jan 2007 21:04:09 -0000 Authentication-Results: pb1.pair.com header.from=info@adaniels.nl; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=info@adaniels.nl; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain adaniels.nl from 82.94.235.198 cause and error) X-PHP-List-Original-Sender: info@adaniels.nl X-Host-Fingerprint: 82.94.235.198 hyak.bean-it.nl Received: from [82.94.235.198] ([82.94.235.198:38919] helo=hyak.bean-it.nl) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 47/59-07357-7C625B54 for ; Mon, 22 Jan 2007 16:04:08 -0500 Received: from [127.0.0.1] (bean-it.xs4all.nl [213.84.27.165]) (authenticated bits=0) by hyak.bean-it.nl (8.13.4/8.13.4/Debian-3sarge3) with ESMTP id l0ML3r3T027012; Mon, 22 Jan 2007 22:03:56 +0100 Message-ID: <45B526AD.2040009@adaniels.nl> Date: Mon, 22 Jan 2007 22:03:41 +0100 User-Agent: Thunderbird 1.5.0.9 (Windows/20061207) MIME-Version: 1.0 To: Lars Schultz CC: Stanislav Malyshev , internals@lists.php.net References: <45B0E1EE.2030102@widescreen.ch> <45B123F5.3070803@zend.com> <45B3929B.8040803@widescreen.ch> <45B51124.90207@zend.com> <45B51AA8.8090307@widescreen.ch> In-Reply-To: <45B51AA8.8090307@widescreen.ch> Content-Type: multipart/alternative; boundary="------------040700080007010507090307" X-Virus-Scanned: by amavisd-new X-Spam-Status: No, score=0.2 required=4.0 tests=BAYES_40,HTML_30_40, HTML_MESSAGE autolearn=ham version=3.1.7 X-Spam-Checker-Version: SpamAssassin 3.1.7 (2006-10-05) on hyak.bean-it.nl Subject: Re: [PHP-DEV] PHP Object-Caching and Reference Counting From: info@adaniels.nl (Arnold Daniels) --------------040700080007010507090307 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi, To get an understanding of zval's and php internal basics, I recommend you read the following tutorials: http://devzone.zend.com/node/view/id/1021 - Part I: Introduction to PHP and Zend http://devzone.zend.com/node/view/id/1022 - Part II: Parameters, Arrays, and ZVALs http://devzone.zend.com/node/view/id/1023 - Part II: Parameters, Arrays, and ZVALs (continued) http://devzone.zend.com/node/view/id/1024 - Part III: Resources (Hmm this is the 3rd time I advertise these tutorials, I should get paid for it :p ) Best regards, Arnold Lars Schultz schreef: > >> That's correct. However, it is not guaranteed that your unset would >> delete last reference - there can be references on stack, in temp >> variables in current expressions being calculated (function call >> could happen in mid-expression), etc. Of course, it might be that >> your code is very controlled so you know it never happens, but as >> general case you can't rely on it. > > Ok. I got your point. You are right that it's hard to predict where > references could be found. > >> Also, if you check only zval refcount, you might unset objects that >> actually are referenced from other places but by different zvals, >> since one object could be referenced by a number of zvals. > > I am not familiar with the term: "zval"...My understanding of php > comes from extensive usage...Can you give me a specific example? > > $foo = new MyObject(); //ref count to Object #1 is 1 > $bar = $foo; //ref count to Object #1 is 2 > if ( ($zapp = $bar)->doIt() ) {...} //ref count is 3 or 4? but it > doesn't matter really... > > I also believe that my reasons for this feature only require that > there are not any less references than are returned by ref_count()...I > am aware that the usage is for quite an advanced concept...but why > shouldn't PHP also be used for this. > > The one argument against this feature that carries the most weight, > for me, is that PHP might change the behaviour of its memory > management and then keeping count of references would be an unecessary > overhead, which might lead to my code not working anymore if the > feature were to be dropped. Are there likely to be any changes in the > future?...and is there an other solution to this concept? I find it > rather neat...;) Especially if you couple it with the magic function > __wake() where the objects re-register themselves in the cache-list... > > class MyObject { > ... > public function __wake(){ > self::$instances[$this->id] = $this; > } > ... > } > ?> > > In this case all objects not referenced by any variable in the > $_SESSION array (or it's descendants), would be destructed at the end > of the script. This way the objects remain unique even across sessions > and some kind of cleaning up is done by the serialization process. The > trouble is that this only works at the end of the script where of > course even the current stack is not used anymore. So I can't use this > principle in a function-call. Or does anyone of you have a different > solution?;) > --------------040700080007010507090307--