Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:25674 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 77027 invoked by uid 1010); 13 Sep 2006 19:56:00 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 77006 invoked from network); 13 Sep 2006 19:56:00 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Sep 2006 19:56:00 -0000 Authentication-Results: pb1.pair.com header.from=tslettebo@broadpark.no; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=tslettebo@broadpark.no; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain broadpark.no from 80.202.4.58 cause and error) X-PHP-List-Original-Sender: tslettebo@broadpark.no X-Host-Fingerprint: 80.202.4.58 osl1smout1.broadpark.no Solaris 9 Received: from [80.202.4.58] ([80.202.4.58:39818] helo=osl1smout1.broadpark.no) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CE/55-45066-C2268054 for ; Wed, 13 Sep 2006 15:55:59 -0400 Received: from osl1sminn1.broadpark.no ([80.202.4.59]) by osl1smout1.broadpark.no (Sun Java System Messaging Server 6.1 HotFix 0.05 (built Oct 21 2004)) with ESMTP id <0J5J000Y9OEM5520@osl1smout1.broadpark.no> for internals@lists.php.net; Wed, 13 Sep 2006 20:51:58 +0200 (CEST) Received: from pc ([80.203.129.59]) by osl1sminn1.broadpark.no (Sun Java System Messaging Server 6.1 HotFix 0.05 (built Oct 21 2004)) with SMTP id <0J5J00584OEMLQ41@osl1sminn1.broadpark.no> for internals@lists.php.net; Wed, 13 Sep 2006 20:51:58 +0200 (CEST) Date: Wed, 13 Sep 2006 20:52:13 +0200 To: Stanislav Malyshev Cc: internals@lists.php.net Message-ID: <002301c6d765$b9c82c10$9a02a8c0@pc> MIME-version: 1.0 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1807 X-Mailer: Microsoft Outlook Express 6.00.2800.1807 Content-type: text/plain; charset=iso-8859-1 Content-transfer-encoding: 7BIT X-Priority: 3 X-MSMail-priority: Normal References: <0ca501c6d709$0cc74020$a900000a@adstate.local> <4508483D.8070504@zend.com> Subject: Re: [PHP-DEV] Const member functions From: tslettebo@broadpark.no (=?iso-8859-1?Q?Terje_Sletteb=F8?=) > > In C++, it's possible to declare member functions "const" meaning they don't > > change the object they operate on. This can help reason about programs, > > because if you have something like (PHP syntax): > > It would be pretty hard to enforce in PHP - how do you know the object > is not changed, without strictly typing all the functions that access > it? Like I've mentioned, I don't know how PHP does this internally, so maybe this is hard to detect (or may result in nontrivial overhead). I'm not sure what you mean by "strictly typing all the functions that access it": The modification detection would likely have to happen at run-time (not compile-time), due to PHP's dynamically typed nature, so I can't see what typing would have to do with it. > Also, while in C++ compiler can benefit from knowing the function is > const - i.e. from knowing nothing was changed by it regarding this > argument - PHP engine hardly can do it. Much, if not almost all, of the benefit of "const" is about program correctness and easier reasoning about programs (if you know something is const, including variables, you know you can rely on them not having been changed, even a zillion lines below where they were defined), i.e. advantages for the _developer_, foremost. It _might_ give some possibilities of optimisation, in a statically typed language, but that's more of a side effect. Regards, Terje