I have an abstract parent class Item
, from which different types of items extend: ItemTypeA
, ItemTypeB
, and ItemTypeC
. From my database result, I have an array:
array(
'item_name' => 'This is the item name',
'item_type' => 'ItemTypeA'
);
In PHP, what's the best way to create the item? Should I do something similar to the following?
static function constructFromDatabase($result){
$type = $result['item_type'];
$item = new $type;
return $item;
}