[eluser]OverZealous[/eluser] @Skipper
This isn't specifically related to DMZ, but try the magic __get method: it's used throughout DMZ to handle relationships and more.
Code:
// in *your* class
public function __get($field) {
if($field == 'inventoryvalue') {
return $this->quantity_on_stock * $this->cost_per_unit;
}
// important: defer to DMZ!
return parent::__get($field);
}
Then you can access it like a field.
Code:
echo $object->inventoryvalue;
If you reference the value a lot, you may want to cache it, by setting $this->inventoryvalue to the result of the multiplication. (The magic __get method is only called if the field does not already exist on the object.)
One more thing: If you want the field to show up in your IDE (assuming you use one), put this in the class's PHPDoc comment: