<?php
class a{
public function __get($key) {
if($key == 'obj') {
if($this->_obj == null) { //PSEUDO this is what I intend to do :)
echo "creating ";
$obj = new StdClass();
$obj->what = get_class($this);
$this->_obj = $obj;
}
return $this->_obj;
}
}
}
class location extends a{
protected $_obj = null;
public function __get($key) {
return parent::__get($key);
}
}
class user extends a{
protected $_obj = null;
public function __get($key) {
return parent::__get($key);
}
}
$l = new location();
echo $l->obj->what . "\n";
$u = new user();
echo $u->obj->what . "\n";
echo $l->obj->what . "\n";
echo $u->obj->what . "\n";
?>