-
Notifications
You must be signed in to change notification settings - Fork 6
/
PropertyObject.inc
47 lines (41 loc) · 1.04 KB
/
PropertyObject.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
/**
* Description of PropertyObject
*
* From example code at http://www.php.net/manual/en/language.oop5.properties.php#98267
*/
abstract class PropertyObject {
private $_construct = FALSE;
protected $_populated = TRUE;
protected function _refresh() {
}
public function __get($name) {
$var_name = "_$name";
if ((!property_exists($this, $var_name) || $this->$var_name == NULL) && !$this->_populated) {
$this->_refresh();
}
if (method_exists($this, ($method = 'get_'.$name))) {
return $this->$method();
}
else return;
}
public function __isset($name) {
if (method_exists($this, ($method = 'isset_'.$name))){
return $this->$method();
}
else return;
}
public function __set($name, $value) {
if (method_exists($this, ($method = 'set_'.$name))) {
$this->$method($value);
}
else {
$this->$name = $value;
}
}
public function __unset($name) {
if (method_exists($this, ($method = 'unset_'.$name))){
$this->$method();
}
}
}