__set and string concatenation

Thomas

New Member
Im' wondering if this is possible:I've successfully used __set() magic method to set values to properties of a class:\[code\]class View{ private $data; public function __set( $key, $value ) { $this->data[$key] = $value; }}\[/code\]So I'm able to:\[code\]$view = new View();$view->whatever = 1234;\[/code\]The problem comes when I want to concatenate a string for example. It seems like __set() is not being called (it's not being called in fact).\[code\]$view = new View();$view->a_string = 'hello everybody'; //Value is set correctly$view->a_string.= '<br>Bye bye!'; //Nothing happens...echo $view->a_string;\[/code\]This outputs "hello everybody". I'm not able to execute __set() in the second assignment.Reading php.net it says that:\[code\]__set() is run when writing data to inaccessible properties.\[/code\]So as *a_string* already exists, __set is not called.My question finally is... how could I achieve that concatenation operation??Note:Ok... Murphy came and gave me the answer as soon as I posted this...The answer (As I understood), is that PHP is not able to decide if *a_string* is available as I didn't defined a __get() method.Defining __get() allows php to find the current value of *a_string*, then uses __set() to concatenate the value.
 
Top