We can't do it for you. Login and vote now.
By mathewbyrne
via matbyrne.com
Published: Apr 22 2008 / 14:29
Modeling real-world objects with computer Data Structures is one of the more fundamental principles of Computer Science. Data Models however are often tied heavily to their storage medium, whether that be an SQL database, files on a filesystem or a web-service. The idea of implementing a Model/Mapper system is to decouple the format in which we wish to manipulate data from the format that we store it.
Comments
antych replied ago:
wtf, use __get, __set and __isset
mathewbyrne replied ago:
You could definitely use __get, __set and __isset, you could even incorporate them into the class I demonstrated. The point isn't to make a Model class that can't be done in other ways, or even to make the highest performing class. It's to provide a framework for extending Models to eventually do things other than get and set with a nice syntax that can do the following:
$model->setField('value')->setFoo(1.5)-> ...
antych replied ago:
You used __call to implement getters and setters, when __get and __set already exist for this purpose, the only thing you gained is fluent interface at a price of verbosity and some messed up code. Don't reinvent square wheels.
Voters For This Link (8)
Voters Against This Link (2)