Created
January 28, 2009 23:36
-
-
Save stuartloxton/54257 to your computer and use it in GitHub Desktop.
An example implementation of Key Value Observing in PHP5.3+
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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