__set and Property Overloading

altedeslego

New Member
\[code\]class object{ public function __construct() {} public function __set($property, $value) { $this->$property = $value; } public function __get($property) { if (isset($property)) return $this->$property; }}\[/code\]I get the concept of Property Overloading now. But I'm not entirely sure why the code have double $'s.For example this statement: \[code\]$this->$property = $value;\[/code\] versus the usual \[code\]$this->property = $value;\[/code\]My guess is that the reason why both statement are different is: The \[code\]$this->property = $value\[/code\] statement is use when the class have explicitly defined property. To clarified, code with a property that is explicitly defined:\[code\]class object { private $property; __construct(){} /... setter, getter/ }\[/code\]Where as \[code\]$this->$property = $value;\[/code\] is used for dynamically created property. So \[code\]$this->$property\[/code\] is actually referring to the \[code\]_set\[/code\]'s $property argument. For clarity: \[code\]_set($property,$value)\[/code\], the first \[code\]__set\[/code\] method's argument (bolded). Heck, maybe the code is just creating a new variable named \[code\]$property\[/code\], instead of referring to the 1st argument in the \[code\]__set\[/code\], and \[code\]$this->\[/code\] is just forcing the class to acknowledge that the class have a new property...Anyway, can someone explain this to me? Thanks again in advance!
 
Top