How can a collection class instantiate many objects with one database call?
- by Buttle Butkus
I have a baseClass where I do not want public setters. I have a load($id) method that will retrieve the data for that object from the db.
I have been using static class methods like getBy($property,$values) to return multiple class objects using a single database call. But some people say that static methods are not OOP.
So now I'm trying to create a baseClassCollection that can do the same thing. But it can't, because it cannot access protected setters. I don't want everyone to be able to set the object's data. But it seems that it is an all-or-nothing proposition. I cannot give just the collection class access to the setters.
I've seen a solution using debug_backtrace() but that seems inelegant. I'm moving toward just making the setters public.
Are there any other solutions? Or should I even be looking for other solutions?