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:
<?php
class Test {
  private:public $x = 42;
}

$obj = new Test;
var_dump($obj->x);
?>

Note, that this adheres to the following EBNF:

<property>     := <write_access>+ (':' <read_access>)? '$' <name> ';'
<write_access> := 'var' | 'public' | 'protected' | 'private'
<read_access>  := 'public'
<name>         := [_a-zA_Z][_a-zA_Z0-9]*

Adding 'protected' to <read_access> 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:[EMAIL PROTECTED]

>> 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:

> <?php
> 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

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to