Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:17507 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 21266 invoked by uid 1010); 3 Aug 2005 02:56:29 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 21251 invoked from network); 3 Aug 2005 02:56:29 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Aug 2005 02:56:29 -0000 X-Host-Fingerprint: 69.64.38.41 bluga.net Linux 2.5 (sometimes 2.4) (4) Received: from ([69.64.38.41:48200] helo=bluga.net) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id CA/73-04646-D5230F24 for ; Tue, 02 Aug 2005 22:56:29 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by bluga.net (Postfix) with ESMTP id 09B9D21C81F; Tue, 2 Aug 2005 21:56:11 -0500 (CDT) Received: from bluga.net ([127.0.0.1]) by localhost (bluga.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 15306-12; Tue, 2 Aug 2005 21:56:10 -0500 (CDT) Received: from [67.48.78.159] (CPE-67-48-78-159.neb.res.rr.com [67.48.78.159]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by bluga.net (Postfix) with ESMTP id A39EA21C81C; Tue, 2 Aug 2005 21:56:10 -0500 (CDT) Message-ID: <42F0325A.9070803@php.net> Date: Tue, 02 Aug 2005 22:56:26 -0400 User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Derick Rethans CC: PHP Developers Mailing List References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new using ClamAV at bluga.net Subject: Re: Property Overloading RFC From: cellog@php.net (Greg Beaver) Hi, As for the first question of how to document virtual properties, I have been recommending that users do this textually inside the docblock for __get()/__set(). This is actually ideal in almost every case, as anyone using __get()/__set() for finite, concrete properties should almost definitely be instead using plain old properties. I wonder if adding this language feature might be a bit too hopeful. For instance, most implementations I have seen of __get()/__set() use them because it isn't possible to know the names of the variables in advance. Simplexml and ext/soap are great examples of extensions that were they implemented in userspace would not be able to use the abstract/virtual keyword proposed because until the specific class is instantiated, one can't know what they will be working with. The Savant template engine may use them for grabbing filtered variables in the future, another good example of "you must document this with prose, not with program syntax". Having said this, if the proposal continues, I do have some suggestions. 2) isAbstract($name))) { /* throw error */ } } } ?> or isVirtual($name))) { /* throw error */ } } } ?> I prefer the 2nd, as it will not confuse with abstract classes (and it will definitely confuse users if we start mixing metaphors programmatically). I also prefer $this-> to self:: as it will allow (as James Crumpton raised) inheritance without redefinition of __get()/__set(). > > - Problem 3 can be solved by: > * allowing optional by-ref parameters to the __set > and __get function, so that their signatures become: > > function __set($name, $value [, &$error] ) > function __get($name [, &$error] ) > > If the parameter is not given things behave just like they do now -> __set > and __get can not throw meaningful errors with the correct file/line of the > conflicting statement > > If the parameter is used in the function's declaration and is set to > "false" when the __set or __get function returns, the engine can throw an > error on the assignment line with the correct file/line combination. If > it's set to "true" (or "null") then the engine should not throw any error. > > * Use a different __set and __get function for 'abstract' properties, then > the engine can already determine if you're doing something wrong before > executing the __set and __get methods. It seems to me the best solution would be to allow error to be set to false or an exception object, which would be then thrown as if it was on the offending line. This would allow the user to customize the error message as well as the line/file. Greg