Please see my comment to the question. Apparently, PHP lacks most of expressive power of "serious" OOP languages. First of all, there are no the property abstraction with side effect implementation using setters/getters. So, one obvious solution is to use explicit functions instead of fields to represent your properties. That is, a non-private function
getImages
can be used to represent
images
. This function will just return the reference to your image container referenced by
images
, but if the container is not yet created, create it. Here is some code sample:
http://stackoverflow.com/questions/19620868/lazy-evaluation-container-for-dynamic-programming[
^].
I wish I could invent something more elegant, but PHP language itself is very, very limiting. Of course it's always possible to invent something way more complex and generic, some "PropertyManager", but then the question would be: does it worth the effort?
—SA