hi all i have problem how to use __get and __set methods in PHP i have diffiulty to understand this magic methods I need definitions of this methods in a broad range Thanks beforehands
[code=php] <?php class Foo { private $bar = 0; // cannot normally be accessed outside of the class public function __set($var, $value) { if ($var == 'bar') { // force value to be integer $this->$var = (int)$value; } else { throw new Exception("Invalid varname '$var'"); } } public function __get($var) { if ($var == 'bar') { return $this->$var; } throw new Exception("Invalid varname '$var'"); } } try { $test = new Foo(); $test->bar = 99; echo $test->bar; // 99 echo "<br />n"; $test->bar = '123.456'; echo $test->bar; // 123 $test->xxx = 333; // throws exception } catch(Exception $e) { user_error($e); } [/code]
Thank you i just understood[/QUOTE]
Help @azegurb spread the word by sharing this article on Twitter...