I'm still trying to wrap my head around OOP. All of the following examples work, of course, but is there one (or possibly another) that best exemplifies OOP concepts?
/**
* For the following examples the Image class queries an image
* and associated info from a database, which is passed on
* instantiation via dependency injection.
*/
$image = new Image(new Db());
Example 1:
if ($image->setImageId($id, $size)) {
header('content-type: ' . $image->content_type);
header('content-length: ' . $image->length);
echo $image->getBytes();
}
Example 2:
if ($image_info = $image->getImageInfoByIdAndSize($id, $size)) {
header('content-type: ' . $image_info->content_type);
header('content-length: ' . $image_info->length);
echo $image->getImageBytesByIdAndSize($id, $size);
}
Example 3:
$image->setImageIdAndSize($id, $size);
if ($image_info = $image->getImageInfo()) {
header('content-type: ' . $image_info->content_type);
header('content-length: ' . $image_info->length);
echo $image->getImageBytes();
}