?php class OO {var $a = 111; var $elem = array('b '= 9, 'c' = 42); / / Callback method for getting a property function __get($prop_name, $prop_value) {if (isset($this - elem[$prop_name])) {$prop_value = $this - elem[$prop_name]; return true;} else {return false;}} / / Callback method for setting a property function __set($prop_name, $prop_value) {$this - elem[$prop_name] = $prop_value; return true;}} / / Here we overload the OO object overload('OO'); $o = new OO; print "\$o - a: $o - a\n"; / / print: $o - a: print "\$o - b: $o - b\n"; / / print: $o - b:
?php class OO {var $a = 111; var $elem = array('b '= 9, 'c' = 42); / / Fonction de callback pour la lecture de membre function __get($prop_name, $prop_value) {if (isset($this - elem[$prop_name])) {$prop_value = $this - elem[$prop_name]; return true;} else {return false;}} / / Fonction de callback pour l 'eacute;criture de membre function __set($prop_name, $prop_value) {$this - elem[$prop_name] = $prop_value; return true;}} / / Ici, l'initiation de l'overload overload('OO'); $o = new OO; print "\$o - a: $o - a\n"; / / print: $o - a: print "\$o - b: $o - b\n"; / / print: $o - b: