fork download
  1. <?php
  2.  
  3. class Foo {
  4. private $values = array();
  5. public function __get($name) { return $this->values[$name] + 1; }
  6. public function __set($name, $val) { $this->values[$name] = $val; }
  7. }
  8.  
  9. $foo = new Foo;
  10. $foo->test = 1;
  11. echo "The retrieved value should be 2: $foo->test\n";
  12.  
  13. // And now...
  14. $val = $foo->bar = 1;
  15. echo "For good or for worse, \$val is $val and \$foo->bar is $foo->bar\n";
  16.  
Success #stdin #stdout 0.02s 13064KB
stdin
Standard input is empty
stdout
The retrieved value should be 2: 2
For good or for worse, $val is 1 and $foo->bar is 2