private, protected, readonly, public

php.internals

Jason Garber

20 years ago
Hello internals, __get() and __set() are great, but 90% of the time, I find myself using them to create public readonly properties. The only problem with this is it is horridly inefficient, consuming at least 1 function call and one switch statement (or equiv) per property read. Would it be possible to create a new object property attribute: readonly class xx { readonly $bar; } $o = new xx(); $o->bar = 10;
>>> FATAL ERROR
This way, PHP would allow reading (as if it were public), but only allow writing from within the class. I think it could really boost performance of complicated application logic that wishes to enforce good visibility. Comments? PS. What brought this up was some serious performance issues in a piece of code that I am working with - most of which can be tied back to __get() performance.
-- Best regards, Jason Garber mailto:jason@ionzoft.com IonZoft, Inc.

Etienne Kneuss

20 years ago
Hi, my 2c: 1) it shouldn't replace the visibility definition: we could also have protected readonly properties. 2) It only requires a bit of discipline, not to edit the properties you want to be readonly. 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. 4) if you're looking for strong performances, use (2) and don't care about readonly. Such code would be a way to emulate them in userland, which produces overhead of course, but probably less than your switch: class foo { protected $_readonlyVars = array('name1' => true, 'name2' => false); protected $_vars = array('name1' => 'value1', 'name2' => 'value2'); public function __set($name, $value) { if(empty($this->_readonlyVars[$name])) { $this->_vars[$name] = $value; } } public function __get($name) { if(isset($this->_vars[$name])) { return $this->_vars[$name]; } } } $o = new foo; $o->name1 = $o->name2 = 'newvalue'; echo $o->name1,'-', $o->name2; // value1-newvalue Jason Garber a écrit :
> Hello internals, > > __get() and __set() are great, but 90% of the time, I find myself > using them to create public readonly properties. > > The only problem with this is it is horridly inefficient, consuming > at least 1 function call and one switch statement (or equiv) per > property read. > > Would it be possible to create a new object property attribute: > readonly > > class xx > { > readonly $bar; > } > > $o = new xx(); > > $o->bar = 10; > >>> FATAL ERROR > > > This way, PHP would allow reading (as if it were public), but only > allow writing from within the class. > > I think it could really boost performance of complicated application > logic that wishes to enforce good visibility. > > Comments? > > PS. What brought this up was some serious performance issues in a > piece of code that I am working with - most of which can be tied > back to __get() performance. > >
-- Etienne Kneuss http://www.colder.ch/ colder@php.net

Hartmut Holzgraefe

20 years ago
Etienne Kneuss wrote:
> 2) It only requires a bit of discipline, not to edit the properties you > want to be readonly.
well, then we don't need private/protected/public at all, as it only requires a bit of discipline not to access the properties you want to be visible to the class or its children only?
-- Hartmut Holzgraefe, Senior Support Engineer . MySQL AB, www.mysql.com Are you certified? http://www.mysql.com/training/certification

Etienne Kneuss

20 years ago
Yes, I also consider the visibility as a candy functionality.
> Etienne Kneuss wrote: >> 2) It only requires a bit of discipline, not to edit the properties you >> want to be readonly. > > well, then we don't need private/protected/public at all, > as it only requires a bit of discipline not to access the > properties you want to be visible to the class or its > children only?
-- Etienne Kneuss http://www.colder.ch/ colder@php.net

Gareth Ardron

20 years ago
Etienne Kneuss wrote:
> Yes, I also consider the visibility as a candy functionality. > > >> Etienne Kneuss wrote: >> >>> 2) It only requires a bit of discipline, not to edit the properties you >>> want to be readonly. >>> >> well, then we don't need private/protected/public at all, >> as it only requires a bit of discipline not to access the >> properties you want to be visible to the class or its >> children only? >>
It's only candy functionality when you're not in a position of possibly having to hand the application you've written over to a bunch of developers you don't know, who probably won't read the docs and will do things the wrong way. Having visibility in this case really, really helps - and more than anything, it covers my back when they screw up. Yeah, if all you're writing is small apps, you're not going to have an issue - or if you're only using a handful of developers, it won't be an issue, but it's a very good thing when the future development cycle of a product isn't clear.

Marcus Börger

20 years ago
Hello Etienne, 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.
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.
We could add this to reflection api easily. Best regards, Marcus

Jason Garber

20 years ago
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. MB> Best regards, MB> Marcus

Marcus Börger

20 years ago
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: <?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

Marcus Börger

20 years ago
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: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:
> <?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

Marcus Börger

20 years ago
Hello internals, sorry the patch got lost somehow, here it is :-) regards marcus Sunday, May 14, 2006, 10:12:12 PM, you wrote:
> 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: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:
>> <?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
Best regards, Marcus

Marcus Börger

20 years ago
Hello Andi, hello List, this patch does not introduce a new keywors and thus comes with a whole set of problems canceled out already. Anyway it adds complexity to what you have to learn about PHP. In fact seeing two visibility keywords separated by a colon should be easy enough to understand for everybody. But noone would know which side is the read and which is the write side. The keyword 'readable' on the otherhand would be absolutly clear even for beginners after at least thinking for a second. But oh i said thinking :-) The patch also allows any combinations in later version should we ever want to go that road which i do not see any sense in. E.g. private:public and protected:public make sense to me and are often a nice optimization and also a nice shortcu in development and easing the pain especially for beginners or small hacked to gether stuff. However, the reason i write this mail is that you said there could be problems. Well this is deply integrated in the handlers and they don't let you out. In other words if this stuff is not working then the whole PHP 5+ object model is broken. Or in other words, if this is broken alot of other stuff regarding object handling is already broken. best regards marcus btw, i wonder where the people are that usually complain about my patches? Is this finally something most people like? Sunday, May 14, 2006, 10:21:54 PM, you wrote:
> Hello internals,
> sorry the patch got lost somehow, here it is :-)
> regards > marcus
> Sunday, May 14, 2006, 10:12:12 PM, you wrote:
>> 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: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:
>>> <?php >>> class Test { >>> private readonly $x = 42; >>> }
>>> $obj = new Test; >>> var_dump($obj->x);
?>>>>

D. Dante Lorenso

20 years ago
Marcus Boerger wrote:
> btw, i wonder where the people are that usually complain about my patches? > Is this finally something most people like? >
Maybe you built a nuclear power plant. Dante

Zeev Suraski

20 years ago
At 21:33 16/05/2006, Marcus Boerger wrote:
>Hello Andi, hello List, > > this patch does not introduce a new keywors and thus comes with a whole >set of problems canceled out already.
I think that it's absolutely horrible syntax wise :) private:public $foo?
> Anyway it adds complexity to what you >have to learn about PHP. In fact seeing two visibility keywords separated >by a colon should be easy enough to understand for everybody.
I'll be blunt as it's late here, but that's just ******** (decided to censor myself). I for one would never guess what it means (well actually my guess would be something to do with inheritance). Either I'm an idiot, or you have a serious problem estimating what's obvious and what's not... And before you say anything, no, I'm not an idiot :)
>But noone >would know which side is the read and which is the write side. The keyword >'readable' on the otherhand would be absolutly clear even for beginners >after at least thinking for a second. But oh i said thinking :-)
Again, ******** in my humble opinion. Readable from where? Does it mean it's otherwise not readable? Does it mean that it's not writable? From where? How does it relate to inheritance? There's no way in hell to understand it without reading up on it, and even then, it's not very easy to remember. You've seen today someone saying that PPP is often tricky as it is. So those 'horror stories' I'm telling are very much a reality. You're suggesting that doesn't complicate it further? Please.
>The patch also allows any combinations in later version should we ever want >to go that road which i do not see any sense in. E.g. private:public and >protected:public make sense to me and are often a nice optimization and >also a nice shortcu in development and easing the pain especially for >beginners or small hacked to gether stuff.
Look, don't get me wrong, but if you pursue this private:public thingie, I'll have to hurt you next time I see you :) Just no way.
>However, the reason i write this mail is that you said there could be >problems. Well this is deply integrated in the handlers and they don't >let you out. In other words if this stuff is not working then the whole >PHP 5+ object model is broken. Or in other words, if this is broken alot >of other stuff regarding object handling is already broken.
You're probably right about this one. You can already return a reference to a private variable today and change it. Andi - did you mean something else? Zeev

Andi Gutmans

20 years ago
I can't quite explain it but for me the ability to work-around private with methods which are able to access the private variable, is different than marking a property as read-only but it not being read-only in all semantics. Probably because private variables do often have getters and setters, whereas something which is marked as read-only (like a harddrive) tends to be read-only always. Andi At 02:08 PM 5/16/2006, Zeev Suraski wrote:

Marcus Börger

20 years ago
Hello Zeev, Tuesday, May 16, 2006, 11:08:57 PM, you wrote:
>> Anyway it adds complexity to what you >>have to learn about PHP. In fact seeing two visibility keywords separated >>by a colon should be easy enough to understand for everybody.
> I'll be blunt as it's late here, but that's just ******** (decided to > censor myself). I for one would never guess what it means (well > actually my guess would be something to do with inheritance). Either > I'm an idiot, or you have a serious problem estimating what's obvious > and what's not... And before you say anything, no, I'm not an idiot :)
I would never allow myself to even think that. Maybe you're right and it is just obvious to me as i wrote the patch.
>>But noone >>would know which side is the read and which is the write side. The keyword >>'readable' on the otherhand would be absolutly clear even for beginners >>after at least thinking for a second. But oh i said thinking :-)
> Again, ******** in my humble opinion. Readable from where? Does it > mean it's otherwise not readable? Does it mean that it's not > writable? From where? How does it relate to inheritance?
Na 'readable' means readable whatever i said elsewhere, no? Not logical?
> There's no way in hell to understand it without reading up on it, > and even then, it's not very easy to remember.
> You've seen today someone saying that PPP is often tricky as it > is. So those 'horror stories' I'm telling are very much a > reality. You're suggesting that doesn't complicate it further? Please.
Erm i heared somebody asking for 'friend' during php 5.0 development; And it wasn't me, i swear.
>>The patch also allows any combinations in later version should we ever want >>to go that road which i do not see any sense in. E.g. private:public and >>protected:public make sense to me and are often a nice optimization and >>also a nice shortcu in development and easing the pain especially for >>beginners or small hacked to gether stuff.
> Look, don't get me wrong, but if you pursue this private:public > thingie, I'll have to hurt you next time I see you :) Just no way.
ouch! Well, it's just a stupid patch that comes without a new keyword. Mayke it 'private readable'. Btw, you asked for for a new visibility keyword starting with P: Promulgate, Popularize, Proclaim, Pliable. Those are at least remotely related to what they should express. Actually promulgate is in my humble opinion quite close :-) And since you get what you deserver you'll find the updated patch attached. Before you ask making it a single keyword on its own and giving the member private or protected write visibility is of cause very easy, too.
>>However, the reason i write this mail is that you said there could be >>problems. Well this is deply integrated in the handlers and they don't >>let you out. In other words if this stuff is not working then the whole >>PHP 5+ object model is broken. Or in other words, if this is broken alot >>of other stuff regarding object handling is already broken.
> You're probably right about this one. You can already return a > reference to a private variable today and change it. Andi - did you > mean something else?
Best regards, Marcus before anyone gets that wrong again, i am having fun with the patch.

Ron Korving

20 years ago
In C++ you'd use private for this. All object members are readable, but modifyability depends on the relation between the caller and the object. I don't quite understand why PHP is doing it differently. - Ron "Jason Garber" <jason@ionzoft.com> schreef in bericht news:785810036.20060511193536@ionzoft.com...

Hartmut Holzgraefe

20 years ago
Ron Korving wrote:
> In C++ you'd use private for this. All object members are readable, ...
Could you elaborate on this?
-- Hartmut Holzgraefe, Senior Support Engineer . MySQL AB, www.mysql.com Are you certified? http://www.mysql.com/training/certification

Ron Korving

20 years ago
My bad, you are absolutely right, I must be confused with another language, but I wonder which one.... odd. Ron "Hartmut Holzgraefe" <hartmut@php.net> wrote in message news:4465FBED.8070205@php.net...

Marcus Börger

20 years ago
Hello Ron, hehe, maybe confused with delphi or borlands c++ additons? Speaking of which before we add 'readonly' we should go for full property support but on the other hand that might be a little bit too much until php is used with code generators and gui designers where code inspectors execute and manipulate source/code while developing. Ups wrong tool.... regards marcus Saturday, May 13, 2006, 8:52:39 PM, you wrote:
> My bad, you are absolutely right, I must be confused with another language, > but I wonder which one.... odd.
> Ron
> "Hartmut Holzgraefe" <hartmut@php.net> wrote in message > news:4465FBED.8070205@php.net... >> Ron Korving wrote: >> > In C++ you'd use private for this. All object members are readable, ... >> >> Could you elaborate on this? >> >> -- >> Hartmut Holzgraefe, Senior Support Engineer . >> MySQL AB, www.mysql.com >> >> Are you certified? http://www.mysql.com/training/certification
Best regards, Marcus

Mauro Nicolás Infantino

20 years ago
Marcus, Just my two cents... Maybe it's better to see it the other way round. Maybe php won't be used with code generators and gui designers until full property support is developed. Marcus Boerger wrote:
> Hello Ron, > > hehe, maybe confused with delphi or borlands c++ additons? > Speaking of > which before we add 'readonly' we should go for full property > support but > on the other hand that might be a little bit too much until > php is used > with code generators and gui designers where code inspectors > execute and > manipulate source/code while developing. Ups wrong tool.... > > regards > marcus
-- Checked by AVG Free Edition. Version: 7.1.392 / Virus Database: 268.5.6/338 - Release Date: 12/05/2006

Jeff Moore

20 years ago
On May 13, 2006, at 7:18 PM, Marcus Boerger wrote:
> hehe, maybe confused with delphi or borlands c++ additons? Speaking > of > which before we add 'readonly' we should go for full property support > but > on the other hand that might be a little bit too much until php is used > with code generators and gui designers where code inspectors execute > and > manipulate source/code while developing.
Hi Marcus, Full property support is high on my wishlist for 6.0. I was a Delphi programmer for 5 years and miss properties. C#, Ruby, and Java all have built in property support with accessor methods, or at least a single standard implementation that all the tools can get behind. __get and __set leave you in complete limbo for both source code and reflection based tools. I think the language support has to come before the tools. I think this can be implemented by adding a getter and setter field to zend_property_info, then checking for it in zend_std_read_property, etc. Although, I'm sure there's more to it than that. Such an implementation would probably be 3 to 4 times faster than __get(). No switch, no $name parameter, perhaps no guard logic. Checking for a getter or setter in zend_property_info would be a fast boolean test on a data structure thats already available, so I believe there would be little overhead. Here are a few use cases and syntax suggestions... A. Declaring a property with accessor methods: public $foo read getFoo write setFoo; B. Read only property with accessor method could be declared: public $foo read getFoo; C. A shortcut notation could automatically generate the accessor method based on another property: public $foo read $_foo; // internally generated method ala C# property implementation: // public function __get_foo() { return $this->$_foo; } D. Similar to read only, you could have split visibility, for example, a public getter and a protected setter: public $foo read getFoo write protected setFoo; // Handy use case, not crazy about this syntax public function getFoo() { return $this->_foo; } protected function setFoo($value) { $this->_foo = $value } E. To avoid warnings, declare the internal storage, too: public $foo read $_foo write setFoo, protected $_foo; public $foo read $_foo, protected $_foo; // readonly F. Properties with accessor methods cannot be directly initialized. Their internal storage can, however: public $foo read $_foo write setFoo, protected $_foo = 'bar'; G. calling unset() on a property with accessor methods could call the setter with NULL. H. calling isset() on a property with accessor methods returns FALSE if the property does not exist, otherwise calls the getter and compares against NULL for compatibility purposes. (?) I. calling property_exists() on a property with accessor methods would always return TRUE. J. The setter and getter could be inspected via ReflectionProperty. K. Unlike __get, subclass property definitions could override the parent declarations: class Foo { public $prop; } class Bar extends Foo { public $prop read getProp write setProp; ... } L. An abstract class need not declare the actual accessor methods, they could be added as abstract by default: abstract class Bar { public $foo read getFoo write setFoo; } Just a few thoughts. I am sure there are other possibilities for the same use cases. Best Regards, Jeff

Jared Williams

20 years ago
> On May 13, 2006, at 7:18 PM, Marcus Boerger wrote: > > > hehe, maybe confused with delphi or borlands c++ > additons? Speaking > > of which before we add 'readonly' we should go for full property > > support but on the other hand that might be a little bit too much > > until php is used with code generators and gui designers where code > > inspectors execute and manipulate source/code while developing. > > Hi Marcus, > > Full property support is high on my wishlist for 6.0. I was a > Delphi programmer for 5 years and miss properties. C#, Ruby, > and Java all have built in property support with accessor > methods, or at least a single standard implementation that > all the tools can get behind. > __get and __set leave you in complete limbo for both source > code and reflection based tools. I think the language > support has to come before the tools. > > I think this can be implemented by adding a getter and setter > field to zend_property_info, then checking for it in > zend_std_read_property, etc. Although, I'm sure there's more > to it than that. Such an implementation would probably be 3 > to 4 times faster than __get(). No switch, no $name > parameter, perhaps no guard logic. Checking for a getter or > setter in zend_property_info would be a fast boolean test on > a data structure thats already available, so I believe there > would be little overhead. > > Here are a few use cases and syntax suggestions... > > A. Declaring a property with accessor methods: > > public $foo read getFoo write setFoo; > > B. Read only property with accessor method could be declared: > > public $foo read getFoo; > > C. A shortcut notation could automatically generate the > accessor method based on another property: > > public $foo read $_foo; > // internally generated method ala C# property implementation: > // public function __get_foo() { return $this->$_foo; } > > D. Similar to read only, you could have split visibility, for > example, a public getter and a protected setter: > > public $foo read getFoo write protected setFoo; // Handy use > case, not crazy about this syntax public function getFoo() { > return $this->_foo; } protected function setFoo($value) { > $this->_foo = $value } > > E. To avoid warnings, declare the internal storage, too: > > public $foo read $_foo write setFoo, protected $_foo; > public $foo read $_foo, protected $_foo; // readonly > > F. Properties with accessor methods cannot be directly initialized. > Their internal storage can, however: > > public $foo read $_foo write setFoo, protected $_foo = 'bar'; > > G. calling unset() on a property with accessor methods could > call the setter with NULL. > > H. calling isset() on a property with accessor methods > returns FALSE if the property does not exist, otherwise calls > the getter and compares against NULL for compatibility purposes. (?) > > I. calling property_exists() on a property with accessor > methods would always return TRUE. > > J. The setter and getter could be inspected via ReflectionProperty. > > K. Unlike __get, subclass property definitions could override > the parent declarations: > > class Foo { public $prop; } > class Bar extends Foo { public $prop read getProp write > setProp; ... } > > L. An abstract class need not declare the actual accessor > methods, they could be added as abstract by default: > > abstract class Bar { public $foo read getFoo write setFoo; } >
Yes, full property support would be nice. Though not to keen on that syntax, but can't think of anything nicer as yet :) Haxe ( http://www.haxe.org/ref#properties ) has something like public $prop(getter, setter); Where getter and setter can be a method name, null for not allowed, default for basic accessor, which is less to type, but still not that nice. Jared

Ron Korving

20 years ago
Likely Delphi yeah :) Ron "Marcus Boerger" <helly@php.net> schreef in bericht news:1771237045.20060514011813@marcus-boerger.de...

Andi Gutmans

20 years ago
I can see where it could come in handy but I honestly think it'd be bloat. We have to relax with the OO features because the increased code size has already made it harder to maintain and it has the potential to make PHP far more complicated than what it should be. At 04:35 PM 5/11/2006, Jason Garber wrote:

Sara Golemon

20 years ago
>> __get() and __set() are great, but 90% of the time, I find myself >> using them to create public readonly properties. >> >I can see where it could come in handy but I honestly think it'd be bloat. > We have to relax with the OO features because the increased code size has > already made it harder to maintain and it has the potential to make PHP > far more complicated than what it should be. >
An extension could accomplish this by exporting an interface which overrides the object's read_property() method. One could "flag" which properties are allowed to be accessed r/o by giving them a distinct name e.g.: class foo implements ReadOnlyProperties { private $__ro__bar; function __construct($val) { $this->__ro__bar = $val; } } $f = new foo(123); var_dump($f->bar); The special getter sees that bar isn't in the properties table and looks for __ro__bar instead (overriding visibility restrictions in the process). Since there's no write_property override, the prop remains unwritable from outside of the object. -Sara

Marcus Börger

20 years ago
Hello Sara, while all what you wrote is doable i'd suggest a slightly different approach. If the name of the variable is prefixed with "r_" and written from outside the class an error will be issued. There's only one thing to be considered. The proposal cannot work for overloaded internal objects like those in ext/dom for example. Friday, May 12, 2006, 6:14:20 PM, you wrote:
>>> __get() and __set() are great, but 90% of the time, I find myself >>> using them to create public readonly properties. >>> >>I can see where it could come in handy but I honestly think it'd be bloat. >> We have to relax with the OO features because the increased code size has >> already made it harder to maintain and it has the potential to make PHP >> far more complicated than what it should be. >> > An extension could accomplish this by exporting an interface which overrides > the object's read_property() method. One could "flag" which properties are > allowed to be accessed r/o by giving them a distinct name e.g.:
> class foo implements ReadOnlyProperties { > private $__ro__bar; > function __construct($val) { > $this->__ro__bar = $val; > } > }
> $f = new foo(123); > var_dump($f->bar);
> The special getter sees that bar isn't in the properties table and looks for > __ro__bar instead (overriding visibility restrictions in the process). > Since there's no write_property override, the prop remains unwritable from > outside of the object.
> -Sara
Best regards, Marcus

Zeev Suraski

20 years ago
I agree with Andi on that (surprise surprise :) What does that give you that class constants don't? Zeev At 18:34 12/05/2006, Andi Gutmans wrote:

Zeev Suraski

20 years ago
Strike that, I was smoking something strong :) Class constants are not really relevant for this use case. At 20:57 15/05/2006, Zeev Suraski wrote:

Hartmut Holzgraefe

20 years ago
Zeev Suraski wrote:
> What does that give you that class constants don't?
i on the other hand fail to see how it is related to class constants at all?
-- Hartmut Holzgraefe, Senior Support Engineer . MySQL AB, www.mysql.com Are you certified? http://www.mysql.com/training/certification

Hartmut Holzgraefe

20 years ago
Hartmut Holzgraefe wrote:
> Zeev Suraski wrote: >> What does that give you that class constants don't? > > i on the other hand fail to see how it is related to class constants > at all?
hm ... this was not supposed to get out as i had seen your reply to yourself ...
-- Hartmut Holzgraefe, Senior Support Engineer . MySQL AB, www.mysql.com Are you certified? http://www.mysql.com/training/certification

Bastian Grupe

20 years ago
Jason Garber wrote:
> > Would it be possible to create a new object property attribute: > readonly > > class xx > { > readonly $bar; > } > > $o = new xx(); > > $o->bar = 10; > >>> FATAL ERROR > > > This way, PHP would allow reading (as if it were public), but only > allow writing from within the class.
Uhh... how about using private and only using a "regular" getter (the Java-style) and no setter? class xx { private $bar; public getBar() { return $bar; } } $o = new xx(); $o->bar = 10; // already emits FATAL ERROR

Hartmut Holzgraefe

20 years ago
Bastian Grupe wrote:
> Uhh... how about using private and only using a "regular" > getter (the Java-style) and no setter? > > class xx > { > private $bar; > > public getBar() { return $bar; } > }
i think you're missing the point, the idea is to *not* have to write that extra getter line ... less typing *and* less error prone ... and easier to read, too IMHO You didn't want to return $bar in your example, you wanted to return $this->bar so you already ran into one of the issues here ;)
-- Hartmut Holzgraefe, Senior Support Engineer . MySQL AB, www.mysql.com Are you certified? http://www.mysql.com/training/certification

Bastian Grupe

20 years ago
Hartmut Holzgraefe wrote:
> Bastian Grupe wrote: > > You didn't want to return $bar in your example, you wanted > to return $this->bar so you already ran into one of the > issues here ;) >
Blame my recent use of Java here ;-) Well, I think the whole point of ppp is to having to use setters and getters consistently. I personally wouldn't like to be able to access some members which are private, and not others. It just *feels* wrong. And I don't know whether or not less typing is really a good argument in this situation (think unreadable code in shortcut-ish programming languages). -- Bastian

Hartmut Holzgraefe

20 years ago
Bastian Grupe wrote:
> Blame my recent use of Java here ;-) > > Well, I think the whole point of ppp is to having to use setters and > getters consistently.
i'm going to blame your use of Java for this one, ppp is way older than the setter/getter fashion and as far as i remember the main reason to introduce the setter/getter pattern into java was to have a standard way for Java IDEs to provide access to Java Bean properties in property dialogs in their GUI design tools
> I personally wouldn't like to be able to access some members which are > private, and not others. It just *feels* wrong.
Think of it as a more fine grained permission system, like unix file attributes. Reading and writing a property value are two different operations and it makes sense to distinguish access rights not only by ownership but also by type of operation.
> And I don't know whether or not less typing is really a good argument in > this situation (think unreadable code in shortcut-ish programming > languages).
Less typing is not an argument by itself, else we'd all do APL But less typing is less error prone (and no, plese *don't* mention auto-completion here ;), it can be less readable, too, and in this special case it spreads information that should be in one place. Maintainability can become an issue, too. Take a look at typical PHP class implementations: they have all properties on top followed by the member functions. So to find out whether a private property is really provite or whether it has a getter or even a setter, too, i would have to browse the full class code. class example { private $foo; private $bar; [... more properties ...] function __construct() {...} function __destruct() {...} function getFoo() {...} [... more code ...] } So $foo is readonly here and $bar is really private. Or wait, maybe we have just overlooked getBar()? With readonly $foo; on the other hand you have all the information in one place. If you want to go the getter/setter path all the way then we wouldn't need all the ppp stuff anymore alltogether, we would just make everything private and have the getter and setter decide (using instanceof on $this etc.) the access rights.
-- Hartmut Holzgraefe, Senior Support Engineer . MySQL AB, www.mysql.com Are you certified? http://www.mysql.com/training/certification

Unnamed Person

20 years ago
It seems to me this would be a great option to add. How difficult would it be? Would it take significant editing of the source code? I don't see the issue in adding it - seems like it would have plenty of places to be used. Though, if it is added, the name 'readonly' seems a little misleading. It gives off the idea of being able to set it, and not edit again, and not only being able to edit it inside the class. On 5/12/06, Hartmut Holzgraefe <hartmut@php.net> wrote:
> > Bastian Grupe wrote: > > Blame my recent use of Java here ;-) > > > > Well, I think the whole point of ppp is to having to use setters and > > getters consistently. > > i'm going to blame your use of Java for this one, ppp is way older > than the setter/getter fashion and as far as i remember the main > reason to introduce the setter/getter pattern into java was to > have a standard way for Java IDEs to provide access to Java Bean > properties in property dialogs in their GUI design tools > > > I personally wouldn't like to be able to access some members which are > > private, and not others. It just *feels* wrong. > > Think of it as a more fine grained permission system, like unix > file attributes. Reading and writing a property value are two > different operations and it makes sense to distinguish access > rights not only by ownership but also by type of operation. > > > And I don't know whether or not less typing is really a good argument in > > this situation (think unreadable code in shortcut-ish programming > > languages). > > Less typing is not an argument by itself, else we'd all do APL > > But less typing is less error prone (and no, plese *don't* mention > auto-completion here ;), it can be less readable, too, and in this > special case it spreads information that should be in one place. > Maintainability can become an issue, too. > > Take a look at typical PHP class implementations: they have > all properties on top followed by the member functions. So to find > out whether a private property is really provite or whether it has > a getter or even a setter, too, i would have to browse the full > class code. > > class example { > private $foo; > private $bar; > [... more properties ...] > > function __construct() {...} > function __destruct() {...} > > function getFoo() {...} > > [... more code ...] > } > > So $foo is readonly here and $bar is really private. Or wait, > maybe we have just overlooked getBar()? > > With > > readonly $foo; > > on the other hand you have all the information in one place. > > If you want to go the getter/setter path all the way then we > wouldn't need all the ppp stuff anymore alltogether, we would > just make everything private and have the getter and setter > decide (using instanceof on $this etc.) the access rights. > > > -- > Hartmut Holzgraefe, Senior Support Engineer . > MySQL AB, www.mysql.com > > Are you certified? http://www.mysql.com/training/certification > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >
-- ------------------------------------ Graham Christensen www.itrebal.com www.iamgraham.net

Jason Garber

20 years ago
Hello, PHP implements many features, and skips many features. I think the rule of thumb needs to be that if a feature is implemented, finish it. For example, if you provide __get() and __set(), provide an efficient way of handling the normal use case. If you start triggering an E_NOTICE when an undefined variable is accessed, then provide an easy way to access variables that may or may not be set. If you provide a __tostring() method, then finish it so that is gets called when an object is cast to a string, concatenated with a string, as well as being output with echo, print. There are a lot of casual users of PHP. There are also the people out there who are buying the Zend products, buying the MySQL support contracts, using PHP at Yahoo! -- the people who have chosen to use PHP OVER Java/.NET/Perl, because it is a great language -- the people who need the completed features because they are running multi-million-dollar businesses on this platform. Take a step back and truly evaluate why someone in a demanding situation might want every bit of performance and readability that they can squeeze out of *existing* language features. I'm not talking about adding hundreds of new features, or turning PHP into the next java. It's about real business cases. It's not about what YOU WOULD NOT use, it's about what a lot of people need.
-- Best regards, Jason Garber mailto:jason@ionzoft.com IonZoft, Inc. Friday, May 12, 2006, 3:16:27 PM, you wrote: igc> It seems to me this would be a great option to add. How difficult would it igc> be? Would it take significant editing of the source code? I don't see the igc> issue in adding it - seems like it would have plenty of places to be used. igc> Though, if it is added, the name 'readonly' seems a little misleading. It igc> gives off the idea of being able to set it, and not edit again, and not only igc> being able to edit it inside the class. igc> On 5/12/06, Hartmut Holzgraefe <hartmut@php.net> wrote:

Andi Gutmans

20 years ago
I can take any feature in PHP and add features :) At 01:44 PM 5/12/2006, Jason Garber wrote:

D. Dante Lorenso

20 years ago
Andi Gutmans wrote:
> I can take any feature in PHP and add features :)
Is that an offer ;-)? I've got a couple you can add, lol. Dante

Rasmus Lerdorf

20 years ago
Jason Garber wrote:
> There are a lot of casual users of PHP. There are also the people > out there who are buying the Zend products, buying the MySQL support > contracts, using PHP at Yahoo! -- the people who have chosen to use > PHP OVER Java/.NET/Perl, because it is a great language -- the > people who need the completed features because they are running > multi-million-dollar businesses on this platform.
Multi-billion in the case of Yahoo! and we can speak for ourselves. The things you listed are irrelevant to us. We have much bigger fish to fry and we are doing so. -Rasmus

Alan Knowles

20 years ago
Definatly would love to see readonly, It would remove 1000's of lines of useless code from 100's of projects - which might make a few more public PHP projects readable ;) It replaces pointless giberish with something explicit clean and elegant.. Looks alot tidier than getters, or __get kludges. Regards Alan Hartmut Holzgraefe wrote:

Brandon Fosdick

20 years ago
Jason Garber wrote:
> Would it be possible to create a new object property attribute: > readonly
Why not make it a little more generic? Say, make readonly an attribute that applies to the ppp tags as opposed to making it a new access class. Eg. if a member is 'public readonly' then it's read/write for private and protected, but read-only in a public context. Similarly, 'protected readonly' is read/write in a private context, read-only in protected and not visible in public. That would make 'private readonly' read-only for private methods, and not visible to anything else, which is probably only useful for properties generated by extensions. Or is this what you're proposing and I'm just being dense?

Zeev Suraski

20 years ago
I have to say that in second thought (after realizing what you really meant) it sounds like a very useful feature. The main thing that worries me is the complexity to the end user, which is already in a pretty bad shape as it is today, and many people here care very little about it, because they can't relate to beginners and average developers. Private/protected/public is a challenge to many of them (not the theory, real world situations), doubling complexity with a modifier is not a good idea. In order to push complexity down I'd avoid making this yet another modifier, and in fact make this an access level, on par with private/protected/public, that would behave like public, except for when outside the object scope (i.e., have it between protected and public). One of the trickey things would be finding an acceptable name, since 'readonly' implies something which this variable isn't (it's very much writable, from the right places). Maybe something like 'visible' (of course preferably we need to find something that begins with 'p'...) Zeev At 02:35 12/05/2006, Jason Garber wrote:

Jasper Bryant-Greene

20 years ago
-----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 Zeev Suraski wrote:
> I have to say that in second thought (after realizing what you really > meant) it sounds like a very useful feature.
[snip]
> In order to push complexity down I'd avoid making this yet another > modifier, and in fact make this an access level, on par with > private/protected/public, that would behave like public, except for when > outside the object scope (i.e., have it between protected and public). > One of the trickey things would be finding an acceptable name, since > 'readonly' implies something which this variable isn't (it's very much > writable, from the right places). Maybe something like 'visible' (of > course preferably we need to find something that begins with 'p'...)
How about... 'package' ;) Jasper -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFEaPIZFfAeHhDzT4gRA6MwAJ95DrFGcKmn724VR2y8kaKrpNychwCgm4Ep U84/fYGcy2JjbwlIBBlBBqI= =G9a4 -----END PGP SIGNATURE-----

Jason Garber

20 years ago
Hello Zeev, In the same way that public readonly properties would be useful from the global scope, protected readonly properties would be just as useful to those of us who spend their php-lives writing base classes (like me) for others to extend and use. I would imagine that the Zend Framework will encounter the (performance based) need for this eventually - I already have. That being said, an access level that means "public readonly" would be very good - but taking it the whole way would be a lot better. Considering that it is an optional keyword, and will only be used where __get(), __set() used to be used - it won't confuse the end users who do not care about it. (get/set is a lot more complex). Thanks!
-- Best regards, Jason mailto:jason@ionzoft.com Monday, May 15, 2006, 2:15:50 PM, you wrote: ZS> I have to say that in second thought (after realizing what you really ZS> meant) it sounds like a very useful feature. ZS> The main thing that worries me is the complexity to the end user, ZS> which is already in a pretty bad shape as it is today, and many ZS> people here care very little about it, because they can't relate to ZS> beginners and average developers. Private/protected/public is a ZS> challenge to many of them (not the theory, real world situations), ZS> doubling complexity with a modifier is not a good idea. ZS> In order to push complexity down I'd avoid making this yet another ZS> modifier, and in fact make this an access level, on par with ZS> private/protected/public, that would behave like public, except for ZS> when outside the object scope (i.e., have it between protected and ZS> public). One of the trickey things would be finding an acceptable ZS> name, since 'readonly' implies something which this variable isn't ZS> (it's very much writable, from the right places). Maybe something ZS> like 'visible' (of course preferably we need to find something that ZS> begins with 'p'...) ZS> Zeev ZS> At 02:35 12/05/2006, Jason Garber wrote:

Andi Gutmans

20 years ago
Would a method be able to return a writable reference of this readonly property? If not it'd actually be PITA to prevent this. This is one of those questions which can turn a two second patch by Marcus, to an ongoing patch where we continue to fix various places and continue to bloat the language and make it much harder to maintain (& possibly create new inconsistencies). So I suggest that before we run forward it has to be clear exactly what the semantics would be and in what cases it might fail. Then we should consider whether we adopt or reject the idea. Not saying it's a bad idea but as I've said many times in the past, running ahead with an idea like this, without thinking through the implications and edge case semantics is a problem... At 02:43 PM 5/15/2006, Jason Garber wrote:

Andi Gutmans

20 years ago
I suggest to wait for a response about the edge cases question I sent out (i.e. returning a writable reference of this readonly property). I for one haven't quite understood what the semantics will be in all the edge case situations. Although I think the concept is interesting (and somewhat beneficial), I don't want to regret having done it 6 months down the line when people complain it's broken because in edge cases it doesn't work. We need to be sure that the semantics are 100% ok in all cases. Writing a patch is the easy part. The fact that patches can be written doesn't mean we shouldn't be careful about making these changes. We have made too many mistakes in the past which were hard to undo. Andi At 07:12 PM 5/15/2006, Andi Gutmans wrote:

Marcus Börger

20 years ago
Hello Andi, however the past has tought of something. Nobody will test a patch. That said there won't be any feedback until it gets into at least head and people feel confident they should experiment with it. As it stands now you could just take it as a decision against it and be done. best regards marcus Tuesday, May 16, 2006, 10:39:53 PM, you wrote:
> I suggest to wait for a response about the edge cases question I sent > out (i.e. returning a writable reference of this readonly property).
How is a writeable reference a public read variable in php? In php we don't have concept like c++ offeres and even there normally const methods return const references aka read only references.
> I for one haven't quite understood what the semantics will be in all > the edge case situations.
The semantics for the majority seems to be public read. E.g. the language offers a way to circumvent or redefine visibility when reading.
> Although I think the concept is interesting > (and somewhat beneficial), I don't want to regret having done it 6 > months down the line when people complain it's broken because in edge > cases it doesn't work. We need to be sure that the semantics are 100% > ok in all cases. Writing a patch is the easy part.
If that was the case, then why was i the only one to provide a patch like in so many times before. I mean yes it is easy for me, and definitively also for dmitry and sara as well as most likely for you too. But how mayn other people can provide such a patch?
> The fact that > patches can be written doesn't mean we shouldn't be careful about > making these changes. We have made too many mistakes in the past > which were hard to undo.
Yes we have only i don't know what we can really do about. I mean other then discussiong it, see that it is doable and getting a feeling for it? We can apply it or forget it. best regards marcus p.s.: I still have the patches for public/protected/private and those for final and tons of others related to our object model. Want me to use them to drop any feature? :-))

Andi Gutmans

20 years ago
Hi Marcus, I don't see why everything is always personal for you. As I mentioned numerous times in the past, having an in-depth discussion about features, both their implementation, affect on language semantics, and relevance to PHP is very beneficial for all. All I meant was that the implementation is one step (and a very necessary step) but that having a patch doesn't always mean it should be applied right away. I just want to make sure we all think it through and discuss the different cases. You seem to be very hesitant around any discussion of such patches which I don't quite understand. It's not geared towards you but the right thing for a mature project like PHP to do. So it boils down again to the same very relevant question I asked initially. Where do you see the edge cases? Can I return a readonly property by reference, can I assign it by reference? What kind of internal functions/classes need fixing? I think thinking these things through (and I believe you can find the answers for these questions) is the process we should really have in PHP. Such major patches should also discuss the dependencies. What we tend to do is to first commit, and then fix later over a period of a year sometimes even discovering down the road that we have conceptual issues. So I'm really not asking for too much. Just asking to also work on the second part which is defining better the reach of this patch. I think this part needs at least as much effort as the patch itself. Andi At 01:55 PM 5/16/2006, Marcus Boerger wrote:

Marcus Börger

20 years ago
Hello Andi, Tuesday, May 16, 2006, 11:09:51 PM, you wrote:
> Hi Marcus,
> I don't see why everything is always personal for you.
Na. Don't get me wrong here. I am just trying to express that what we did in the past didn't really work out. The conservative behavior of adding new features late if at all resulted in a few problems we might have been able to avoid had we added the stuff earlier. Howver adding everything early is as you correctly said unmaintainable. And i further more have no alternative.
> As I mentioned > numerous times in the past, having an in-depth discussion about > features, both their implementation, affect on language semantics, > and relevance to PHP is very beneficial for all. All I meant was that > the implementation is one step (and a very necessary step) but that > having a patch doesn't always mean it should be applied right away. I > just want to make sure we all think it through and discuss the > different cases.
Discussing it is good as long as we actually agree that it is worth discussing :-)
> So it boils down again to the same very relevant question I asked > initially. Where do you see the edge cases? Can I return a readonly > property by reference, can I assign it by reference?
Nope, no references. References would allow writing. Because PHP doesn't offer readonly variable at all. Which is another reason i went the 'readable' road.
> So I'm really not asking for too much. Just asking to also work on > the second part which is defining better the reach of this patch. I > think this part needs at least as much effort as the patch itself.
I do all i can. I try to get it straight, find a nice semantics buld up my own opinion and the try to convince people of it. Besides that as always i try to correct any technical or theoretical issue i can stand helping more people to understand the matters :-) It's just little but all i can do, sorry :-) Best regards, Marcus

Sebastian Bergmann

20 years ago
Andi Gutmans wrote:
> All I meant was that the implementation is one step (and a very > necessary step) but that having a patch doesn't always mean it should > be applied right away. I just want to make sure we all think it through > and discuss the different cases.
IMHO, it is very cumbersome to follow the discussion of both syntax and semantics implications of such a change to the language on a mailinglist alone. I think a text document maintained in CVS is much better suited for this as it gives you one place to look at for the current state of the discussion (and you can look at the CVS history to see how it evolved).
-- Sebastian Bergmann http://www.sebastian-bergmann.de/ GnuPG Key: 0xB85B5D69 / 27A7 2B14 09E4 98CD 6277 0E5B 6867 C514 B85B 5D69

Ron Korving

20 years ago
This is absolutely true. Besides, adding a new access level automatically implies that you'll probably never be able to extend it to protected as well, because you'd need yet another access level and I really doubt people are going to want to do that. But at that point, it would be too late to revert back to a readonly keyword, since the whole world is using the new publicly readable access level already. Choosing to go for a new access level can turn out to be a really big mistake in the long run. Like you, I don't see why a 'readable' keyword should make things any more complicated for beginners, because indeed, it is optional and beginners will simply not use it. To me, this only shows the strength of PHP: suitable for beginners and suitable for the enterprise. Ron "Jason Garber" <jason@ionzoft.com> schreef in bericht news:1217741491.20060515174322@ionzoft.com...

Christian Schneider

20 years ago
Ron Korving wrote:
> Like you, I don't see why a 'readable' keyword should make things any more > complicated for beginners, because indeed, it is optional and beginners will > simply not use it. To me, this only shows the strength of PHP: suitable for > beginners and suitable for the enterprise.
Learning the language is getting more and more difficult. Defining a variable used to be "var" (or no declaration at all). Then visibility was added (and choosing the right visibility is trickier not only for beginners than you might think), as was "static" and "final". Your argument that all the new constructs can be ignored if not needed has two flaws: a) The language reference gets bloated b) Learning by example (one of the selling points of PHP originally IMHO) is made harder than necessary "Suitable for the enterprise" to me is a bit like "Linux, ready for the desktop": It's missing the point by trying to fit everybody's needs. What happened to the KISS principle and Unix philosophy of doing one thing and doing it right? Just my two cents, - Chris

Zeev Suraski

20 years ago
Ron, As I've said numerous times in the past, it's not about what beginners use or not, it's about whether it's in the language or not. Additional keywords and structures make the language more complicated. It's an axiom. Look at PHP 5 books vs. PHP 4 books, including books for beginners. All of them cover everything, and for a good reason - in the PHP world, you need to be able to understand other people's code at least as much as you have to be able to create new code yourself. Every new construct, every new access level or modifier - become a standard part of the basic-elements that PHP developers have to understand and be aware of. So the 'beginners won't use it' argument simply doesn't hold water, as it will confuse them irregardless. I'm seeing that in practice, in places far, far away from internals@, and there are definitely doubts and worries amongst PHP developers regarding the complexity&purity directions that PHP appears to be taking. Most of the people I talk with are mostly happy with PHP 5 (although there are those who think that PHP 5 already went too far), but a lot of them say that we should not go any further in order to preserve the simplicity. Now, all that said, I'm not certain what's the best option here. In terms of complexity, clearly not adding this modifier is the best approach. There's also the issue Andi mentioned, of the feasibility of creating this patch and maintaining it in an acceptable manner. Assuming we all agree to live forever with the semantics that can be implemented, I for one think it's actually a fairly useful feature, including very much for beginners. Regarding whether it's an access level or a modifier, I think that an access level is better since you don't have to explain a matrix of 6 different behaviors (including one that doesn't make sense, but still requires an explanation), only one more access level. I think we can definitely give up the equivalent of 'readonly protected', and tell people to use protected and restrain themselves in those rare cases where it's needed and use regular protected or __set(). When we make this decision, though, it means that we won't be adding the equivalent of 'readonly protected' in the future either, including when people come along and present a use case where it'd be great to use it. Zeev At 11:44 16/05/2006, Ron Korving wrote:

Ron Korving

20 years ago
"Zeev Suraski" <zeev@zend.com> schreef in bericht news:7.0.1.0.2.20060516133953.09045a30@zend.com...
> ... > Regarding whether it's an access level or a modifier, I think that an > access level is better since you don't have to explain a matrix of 6 > different behaviors (including one that doesn't make sense, but still > requires an explanation), only one more access level. I think we can > definitely give up the equivalent of 'readonly protected', and tell people > to use protected and restrain themselves in those rare cases where it's > needed and use regular protected or __set(). When we make this decision, > though, it means that we won't be adding the equivalent of 'readonly > protected' in the future either, including when people come along and > present a use case where it'd be great to use it. > > Zeev
I don't need this feature, so I'm not suggestion anything just because I'd prefer it that way myself. I'm perfectly happy writing setters and getters. The only reason of my post was that I anticipate disappointment in the long run when, as you confirm yourself, "readonly protected" will become practically impossible (besides which, going beyond ppp just seems a little ugly, but I'm sure that's just a matter of taste). I don't really see the huge deal in that a beginner has to be able to understand every bit of code. That same problem exists with other languages where beginners will have big problems diving into complex code (very much including syntax related complexity, like with c++ templates, macros, ...). The only thing I fear is disappointment in the long run really, because an irriversible unlucky decision was made (magic quotes, parameter order of certain functions). In fact, if you want the easiest solution, I actually think the wrong idea I had about c++ access levels could prove to be useful: What if access levels only mean anything to writing to data members, while all data members are publicly readable? <?php class Foo { private $bar = 5; } $foo = new Foo(); echo $foo->bar; // prints 5 $foo->bar = 4; // error ?> I think backwards compatibility would likely be alright, performance will be fine, there will be no extra keyword, no extra access level, and no need for getter functions. Just an idea. Regards, Ron

Stefan Walk

20 years ago
On 5/16/06, Ron Korving <r.korving@xit.nl> wrote:
> <?php > > class Foo > { > private $bar = 5; > } > > $foo = new Foo(); > echo $foo->bar; // prints 5 > $foo->bar = 4; // error > > ?>
I'm against visible private variables. If they are visible, they are part of the interface of the class, which means changing the implementation means a BC break. If this functionality is going in, please do it only for protected... Regards, Stefan

Ron Korving

20 years ago
That's a good point. It was just an idea really, hoping to provide an easy way out for the whole discussion ;) Ron ""Stefan Walk"" <stefan.walk@gmail.com> schreef in bericht news:4858f9d90605160625u11fcaef8ta07fc199558eca9f@mail.gmail.com... On 5/16/06, Ron Korving <r.korving@xit.nl> wrote:
> <?php > > class Foo > { > private $bar = 5; > } > > $foo = new Foo(); > echo $foo->bar; // prints 5 > $foo->bar = 4; // error > > ?>
I'm against visible private variables. If they are visible, they are part of the interface of the class, which means changing the implementation means a BC break. If this functionality is going in, please do it only for protected... Regards, Stefan

Sebastian Bergmann

20 years ago
Stefan Walk wrote:
> I'm against visible private variables. If they are visible, they are > part of the interface of the class, which means changing the > implementation means a BC break.
This is a valid point against readonly, indeed.
-- Sebastian Bergmann http://www.sebastian-bergmann.de/ GnuPG Key: 0xB85B5D69 / 27A7 2B14 09E4 98CD 6277 0E5B 6867 C514 B85B 5D69

Hartmut Holzgraefe

20 years ago
Sebastian Bergmann wrote:
> Stefan Walk wrote: >> I'm against visible private variables. If they are visible, they are >> part of the interface of the class, which means changing the >> implementation means a BC break. > > This is a valid point against readonly, indeed. >
no, it is a valid point against implicit visibility, not against *declaring* a property as readonly
-- Hartmut Holzgraefe, Senior Support Engineer . MySQL AB, www.mysql.com Are you certified? http://www.mysql.com/training/certification

Richard Lynch

20 years ago
On Tue, May 16, 2006 3:44 am, Ron Korving wrote:
> Like you, I don't see why a 'readable' keyword should make things any > more > complicated for beginners, because indeed, it is optional and > beginners will > simply not use it. To me, this only shows the strength of PHP: > suitable for > beginners and suitable for the enterprise.
To be even more expansive: At whatever level of understanding one has for private/protected/public, I don't think the prefix 'readonly' is going to add any significant complexity to that understanding. The people who have no clue and don't care about all this OOP stuff can ignore that. The goofballs who abuse and mis-use private/protected/public because some book told them it was "good" will be equally liberal with their use of "readonly" and only have themselves to blame when they've painted themselves into a corner (again) The 10% of PHP coders who actually understand p/p/p and even apply it in arguably useful ways will grok readonly just fine. :-) Sufficient examples of the utility of 'readonly' with all levels of p/p/p have convinced this village idiot that it should be a modifier to p/p/p and not some new 'p' wedged in.
-- Like Music? http://l-i-e.com/artists.htm