Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:17493 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 43962 invoked by uid 1010); 2 Aug 2005 14:05:39 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 43947 invoked from network); 2 Aug 2005 14:05:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Aug 2005 14:05:39 -0000 X-Host-Fingerprint: 195.28.69.139 mail.jobtion.com Linux 2.4 w/o timestamps Received: from ([195.28.69.139:54314] helo=sparky.datcon.sk) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 46/64-04646-3BD7FE24 for ; Tue, 02 Aug 2005 10:05:39 -0400 Received: from localhost (localhost [127.0.0.1]) by sparky.datcon.sk (Postfix) with ESMTP id 95498209A9 for ; Tue, 2 Aug 2005 16:05:34 +0200 (CEST) Received: from sparky.datcon.sk ([127.0.0.1]) by localhost (sparky [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 17254-01-5 for ; Tue, 2 Aug 2005 16:05:34 +0200 (CEST) Received: from [172.16.71.217] (adsl90.212-5-195.telecom.sk [212.5.195.90]) by sparky.datcon.sk (Postfix) with ESMTP id 651E6A331 for ; Tue, 2 Aug 2005 16:05:28 +0200 (CEST) Message-ID: <42EF7DAA.5050509@kmit.sk> Date: Tue, 02 Aug 2005 16:05:30 +0200 User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.10) Gecko/20050729 X-Accept-Language: sk, en MIME-Version: 1.0 To: internals@lists.php.net References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: amavisd-new at datcon.sk Subject: Re: [PHP-DEV] Property Overloading RFC From: ondrej@kmit.sk (=?UTF-8?B?T25kcmVqIEl2YW5pxI0=?=) Derick Rethans wrote: > Hello! > > we're finding some problems with property overloading (__get() and > __set()). Here is an RFC describing what we'd like to see changed. > Please comment on this. > > > Introduction: > PHP currently supports property overloading with the magic functions __get() > and __set(). Those methods are called when the code "echo $object->a" or > "$object->a = 42" are executed and the property "a" is not declared in the > class. The magic methods are responsibly for: > - checking if the property actually "exists" > - setting the value or returning the value depending on the action > > Problems: > 1. There is no way to document the 'virtual' properties with any of the existing > documentation tools (such as phpdoc and doxygen) > 2. There is no way how the magic methods know if a specific 'virtual' property > exists or not as those properties are not declared usually - unless you > define an array with property names as a class constant (which is not > allowed either). > 3. There is no way for the magic methods to return a meaningfull error when a > property doesn't "exist". Of course it is possible to throw an error with > "trigger_error" or "throw" in case a property doesn't "exist" in a specific > class, but the file and line numbers would not match the actually get/set > action. debug_backtrace() can be used to retrieve the correct file and line, > but as you have to do this for every class where you want to use setters and > getters *and* you have to implement your own error message rendering > function this is not really a suitable option either. what about: Features: 1) Easy way to document properties 2) No BC break with code relies on __get, __set Clases GetSet0, GetSet1 and GetSet2 are equivalent and third class GetSet3 use different methods to handle $x property; There is a nice way to declare reaonly properties property $x { getMethod } or property $x { getMethod, null } and writeonly propeties :) property $x { null, setMethod } If someone touch undeclared property and class don't have __get/__set Zend engine can raise exception ... It's good way? I don't know. -- Ondrej Ivanic (ondrej@kmit.sk)