[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 Mailing

[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 Mailing

Re: [PHP] magic getter

2012-07-19 Thread Matijn Woudt
On Thu, Jul 19, 2012 at 9:22 PM, Sebastian php-maill...@elygor.de 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

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 red

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') {