Re: [PHP] magic getter

2012-07-19 Thread David Harkness
If you want to block setting of public properties on your class, implement the magic setter. class Foo { private $data = array(); function __get($name) { return $this->data[$name]; } function __set($name, $value) { if ($name != 'foo') {

Re: [PHP] magic getter

2012-07-19 Thread Jim Lucas
On 07/19/2012 12:22 PM, Sebastian wrote: Hi all, is this a bug, or a feature? class Foo { private $data; public function __get($name) { return $this->data[$name]; } } $foo = new Foo(); $foo->color = 'red'; echo $foo->color; I would expect an error, or a least a notice, but it prints out "re

Re: [PHP] magic getter

2012-07-19 Thread Matijn Woudt
On Thu, Jul 19, 2012 at 9:22 PM, Sebastian wrote: > Hi all, > > is this a bug, or a feature? > > class Foo > { > private $data; > > public function __get($name) > { > return $this->data[$name]; > } > } > > $foo = new Foo(); > $foo->color = 'red'; > > echo $foo->color; > > I would expec

[PHP] magic getter

2012-07-19 Thread Sebastian
Hi all, is this a bug, or a feature? class Foo { private $data; public function __get($name) { return $this->data[$name]; } } $foo = new Foo(); $foo->color = 'red'; echo $foo->color; I would expect an error, or a least a notice, but it prints out "red" ... -- PHP General Mailin

[PHP] magic getter

2012-07-19 Thread Sebastian
Hi all, is this a bug, or a feature? class Foo { private $data; public function __get($name) { return $this->data[$name]; } } $foo = new Foo(); $foo->color = 'red'; echo $foo->color; I would expect an error, or a least a notice, but it prints out "red" ... -- PHP General Mailin