Value Object Class
No Comments
Andy
Categories:
code
Tags:
PHP
Value class that hold values. Can be used with any class that returns an array of values
Usage
$temp = new ValueObject( array( "value1" => "value", "value2" => 2, "value3" => 123.123, "value4" => "value" ) ); echo $temp->value1;
Code
class ValueObject {
private $properties = array();
public function __construct($values = array()) {
foreach($values as $key => $value)
$this->properties[$key] = $value;
}
public function __set($key = "", $value = "") {
$this->properties[$key] = $value;
}
public function __get($key = "") {
if(array_key_exists($key, $this->properties))
return $this->properties[$key];
}
}