I have call a function to get the object from MySQL like this..
$product_id = 8;
$product = get_Product($product_id);
then do something with the $product
but now, I want to do this...
print_product_spec($product_id)
print_product_images($product_id)
is it better to pass the product_id to the function and connect to database again? or is it better to just put the object in the parameter and use the object from parameter like this..
//$product = an object
print_product_spec($product)
print_product_images($product)
It's way faster to pass the object to the function rather than executing another DB query. The object will be passed by reference to the function so it won't take more memory nor CPU.