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();}
Which of these OOP examples demonstrate proper OOP concepts?
php;object oriented;object oriented design
I agree with delnan's comment about OOP, and that there's really no such thing as proper OOP concepts, but in terms of general coding principles, I think example 2 is a clear winner compared to the others.Examples 1 & 3 are the same thing with different names.  In this case it's not obvious at all that setting the object's ID and size would cause a database fetch and its other properties to be populated. I've debugged code like this and it's hard to track down exactly what's happening with these kinds of side effects hidden all over the place.Example 2 is a sort of combination of a Data Access Object and a Factory, and these could potentially be separated out, but either way it's more obvious to the reader what is happening.EditHere's an even clearer representation:if ($image = $image_data_access->getImageById($id)) {    $image->scaleTo($size);    header('content-type: ' . $image->content_type);    header('content-length: ' . $image->length);    echo $image->getBytes();}