Re: private, protected, readonly, public

From: Date: Fri, 12 May 2006 15:40:20 +0000
Subject: Re: private, protected, readonly, public
References: 1  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
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

Thread (92 messages)

« previous php.internals (#23309) next »