Re: private $foo

From: Date: Tue, 28 Mar 2006 20:22:37 +0000
Subject: Re: private $foo
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-232766@lists.php.net to get a copy of this message
On Tuesday 28 March 2006 1:12 pm, Jochem Maas wrote: > <?php > > class Foo > { > private $foo = 'foo'; > > function __get($k) > { > if (isset($this->{$k})) { > return $this->{$k}; > } > > throw new Exception("non existing property!"); > } > > function __set($k, $v) > { > if (isset($this->{$k})) { > $this->{$k} = $v; > return; > } > > throw new Exception("non existing property!"); > } > } > > $f = new Foo; > echo $f->foo,"\n"; > $f->foo = "bar"; > echo $f->foo,"\n"; Maybe I'm wrong, but I thought you couldn't use the "$f->foo" to access private variables from outside a class? -- Joe Henry www.celebrityaccess.com jhenry@celebrityaccess.com

« previous php.general (#232766) next »