In which the $table rentals are defined at the very top, once we ought to know which table this unique object works together with.

Now, all common record management techniques are in one location, and techniques specific towards the class are that's defined within their particular child-classes.

The greatest drawback I see here's that data fields are drawn and therefore are exemplified inside the $fields property, so either generic get and hang techniques have to be defined (that we typically do) which almost negates the encapsulation*, or perhaps a method should be defined particularly for every property you want to expose.

Well, make your existence simple and easy , use PHP's miracle over-loading __call approach to create generic getters and setters. You could include the next approach to your "Database Object super-class":

So allow me to explain what's happening here. The miracle __call method will get calls to any object method that doesn't match among the object's concrete techniques. It receives as parameters the title from the method which was known as and a range of its arguments.

The __call method above does a fast substr determine when the method would be a "getter" or "setter" (while using first three letters from the method title). It needs that the $fields array stores lower-situation "property" names (lcfirst) and uses everything following the setter/getter prefix because the expected property title.

If your property matches the getter method then that property it's came back. Otherwise, the SplException BadMethodCallException is tossed. This can be a best practice because the inclusion from the Spl exceptions in PHP.

Likewise a setter method will even toss the SplException InvalidArgumentException if no argument was specified.

PHP's miracle techniques can change your existence. You may also use __get and __set to assign $fields array values similarly without making faux method calls. Get excited :)