Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:23344 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 33860 invoked by uid 1010); 14 May 2006 20:12:19 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 33845 invoked from network); 14 May 2006 20:12:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 May 2006 20:12:18 -0000 X-PHP-List-Original-Sender: helly@php.net X-Host-Fingerprint: 81.169.182.136 ajaxatwork.net Linux 2.4/2.6 Received: from ([81.169.182.136:52740] helo=strato.aixcept.de) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id AC/56-19568-02F87644 for ; Sun, 14 May 2006 16:12:17 -0400 Received: from baumbart.mbo (dslb-084-063-032-006.pools.arcor-ip.net [84.63.32.6]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by strato.aixcept.de (Postfix) with ESMTP id 12BBE35C1E8; Sun, 14 May 2006 22:12:13 +0200 (CEST) Date: Sun, 14 May 2006 22:12:12 +0200 Reply-To: Marcus Boerger X-Priority: 3 (Normal) Message-ID: <31269879.20060514221212@marcus-boerger.de> To: internals@lists.php.net Cc: Jason Garber In-Reply-To: <36828701.20060514110529@marcus-boerger.de> References: <785810036.20060511193536@ionzoft.com> <44647B7A.2070301@php.net> <932738738.20060513112734@marcus-boerger.de> <837405862.20060513223403@ionzoft.com> <36828701.20060514110529@marcus-boerger.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] private, protected, readonly, public From: helly@php.net (Marcus Boerger) Hello guys, after some incantations i came to the attached improved patch that allows to give properties any visibility plus mark them as public readable. The patch also implements the PHP 6.0 todo item 'readonly for overloaded objects'. The code now looks like: x); ?> Note, that this adheres to the following EBNF: := + (':' )? '$' ';' := 'var' | 'public' | 'protected' | 'private' := 'public' := [_a-zA_Z][_a-zA_Z0-9]* Adding 'protected' to is possible to but code wise a tiny bit more complex. Chaging the order is of cause also possible. best regards marcus Sunday, May 14, 2006, 11:05:29 AM, you wrote: > Hello Jason, > Sunday, May 14, 2006, 4:34:03 AM, you wrote: >> Hello Marcus, >> class x >> { >> public readonly $xyz; >> protected readonly $abc; >> } >> Definitions: >> - public readonly - outside class can only read, not write. >> - protected readonly - subclass can only read, not write. >> - private readonly - does not make sense - do not support. >> How difficult would it be to build this into the PHP engine? >> -- >> Best regards, >> Jason mailto:jason@ionzoft.com >> Saturday, May 13, 2006, 5:27:34 AM, you wrote: MB>>> Hello Etienne, MB>>> Friday, May 12, 2006, 2:11:38 PM, you wrote: >>>> Hi, >>>> my 2c: >>>> 1) it shouldn't replace the visibility definition: we could also have >>>> protected readonly properties. MB>>> same here visibility and read/write control are two seperate things. >>>> 3) how would you check if the property if readonly ? Trying it could >>>> result to a Fatal error as you wanted. You would then need a >>>> isReadonly() method/function: the function call wouldn't be spared. MB>>> We could add this to reflection api easily. > Here's your diff to play around :-) > The impact on runtime is a single additional integer check for protected > properties and an additional check for private proeprties where property > access would normally fail. For this 5 minute patch i chose the key word > 'readonly' as supposed. Actually writing the mail took much longer than > brewing the patch and yes i din't care for syntax right now. > php -r 'class T{private readonly $x = 42;} $obj = new T; var_dump($obj->x);' > int(42) > Or readable: > class Test { > private readonly $x = 42; > } > $obj = new Test; > var_dump($obj->x); ?>> > As we have the 'Property overloading RFC' on the 6.0 aganda > we should probably move part of the stuff to 5.2 already and > start with the public read access. > http://oss.backendmedia.com/PhP60 > http://www.zend.com/zend/week/week248.php#Heading3 > Best regards, > Marcus Best regards, Marcus