Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:10234 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 8547 invoked by uid 1010); 1 Jun 2004 23:47:27 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 7682 invoked from network); 1 Jun 2004 23:47:22 -0000 Received: from unknown (HELO distance.intux.org) (213.239.198.8) by pb1.pair.com with SMTP; 1 Jun 2004 23:47:22 -0000 Received: (qmail 28126 invoked from network); 1 Jun 2004 23:43:31 -0000 Received: from unknown (HELO saiwala) (intux?org?fschaper@82.82.158.225) by distance.intux.org with SMTP; 1 Jun 2004 23:43:31 -0000 Message-ID: <007701c44832$8a399250$9d00a8c0@saiwala> To: References: <005e01c447e6$9d28bf40$9d00a8c0@saiwala> <008001c447e7$d80ee9d0$9d00a8c0@saiwala> <1086119310.281.43.camel@localhost> Date: Wed, 2 Jun 2004 01:45:34 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 Subject: Re: [PHP-DEV] delete in PHP From: fschaper@intux.org ("Florian Schaper") Timm Friebe wrote: [...] > In comparison to the proposed "delete", unset() only decreases the > refcount. > > Have a look at the following examples: > > $ php-dev -r 'class Object { function __destruct() { echo > "Destroyed\n"; }} $o= new Object(); unset($o); echo "Shutting > down\n";' > Destroyed > Shutting down > > $ php-dev -r 'class Object { function __destruct() { echo > "Destroyed\n"; }} $o= new Object(); $o2= $o; unset($o); echo > "Shutting down\n";' Shutting down > Destroyed > > In the second example, the destructor is not called until *after* > shutdown. This is the small but noticeable difference between what > Florian wants and what we currently provide. > > While I agree this could be interesting, I'm opposed to a keyword > named "delete". Keywords may not be used as regular method names and > a new keyword "delete" would add more BC breaks for people using > methods called delete(). This: > > class DBConnection { > function insert() { } > function update() { } > function select() { } > function delete() { } > } > > is an example which can be seen in numerous applications. > I really dont't want to warm up an discussion that has already been dealt with, but from my pov. - while I agree one should keep them to a minimum - minor changes are to be excpected in a major jump in version numbers and I'm sure this is not unprecedented. Then again I don't get the eMails from the developers going on about their broken code and I wouldn't want to volunteer for that. For completeness: Proposed behaviour of delete as opposed to unset: $ php-dev -r 'class Object { function __destruct() { echo "Destroyed\n"; }} $o= new Object(); $o2= &$o; delete $o; var_export( $o ); var_export( $o2 ); echo "Shutting down\n";' Destroyed NULL NULL Shutting down > Then again, why doesn't unset() do this? That seems kind of > inconsistent with the object-handle-pass-by-value semantics we have > in PHP5. > > For the time being, using reference operators and setting the instance > to NULL gives you a workaround: > > $ php-dev -r 'class Object { function __destruct() { echo > "Destroyed\n"; }} $o= new Object(); $o2= &$o; $o= NULL; echo > "Shutting down\n";' Destroyed > Shutting down > > Interesting enough (from a user's pov, not the Engine's), unset() will > not do the job: > > $ php-dev -r 'class Object { function __destruct() { echo > "Destroyed\n"; }} $o= new Object(); $o2= &$o; unset($o); echo > "Shutting down\n";' Shutting down > Destroyed I for one could manage without a delete keyword with unset destroying the object referenced - which looks for me a more consistent behaviour as Timm pointed out. ./regards Florian