Re: private, protected, readonly, public
| From: | Ron Korving | Date: | Fri, 12 May 2006 12:34:18 +0000 |
| Subject: | Re: private, protected, readonly, public | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-23302@lists.php.net to get a copy of this message | ||
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...
> 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.