During a discussion, I wasn't sure if I was correct when saying:
"It's better to pass around objects as parameters instead of object ID's."
So I thought I'd ask here for clarification.
What are the advantages of doing this:
public function doSomething(\Item $item)
{
return $item->getSomething() * 2;
}
Over this:
public function doSomething($itemID)
{
$item = \Item::getByID($itemID); // Return an item based on ID
if ($item) // Check the object has been returned
{
return $item->getSomething() * 2;
}
}
Is it true to say that one benefit is you can presume the object will exist, so there is no need to check if it does?