<?php
class MagicObject
{
protected $data = array();
public function __get($property_name)
{
if (isset($this->data[$property_name]))
return $this->data[$property_name];
trigger_error("Getting unavailable property <b>$property_name</b>!", E_USER_ERROR);
return null;
}
public function __set($property_name, $val)
{
if (isset($this->data[$property_name]))
$this->data[$property_name] = $val;
else
trigger_error("Setting unvailable property <b>$property_name</b>!", E_USER_ERROR);
}
public function __isset($property_name)
{
return isset($this->data[$property_name]);
}
public function __unset($property_name)
{
unset($this->data[$property_name]);
}
public function toString()
{
return var_export($this, true);
}
public function __call($function_name, $function_args = null)
{
if( empty($function_name) )
return null;
if( empty($function_args) )
return $this->function_name();
return $this->function_name($function_args);
}
}
?>
|