Skip to content

Instantly share code, notes, and snippets.

@stuartloxton
Created January 28, 2009 23:36
Show Gist options
  • Save stuartloxton/54257 to your computer and use it in GitHub Desktop.
Save stuartloxton/54257 to your computer and use it in GitHub Desktop.
An example implementation of Key Value Observing in PHP5.3+
<?php
class ExampleClass {
private $bindings = array();
public function __set($a, $b) {
$this->$a = $b;
if(is_array($this->bindings[$a])) {
foreach($this->bindings[$a] as $bind) {
$bind['f']($bind['p']);
}
}
}
public function __get($a) {
return $this->$a;
}
public function bind($a, $f, $p=null) {
$this->bindings[$a][] = array(
'f' => $f,
'p' => $p
);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment