Re: DB_DataObject's class generator

From: Date: Wed, 08 Dec 2004 10:32:09 +0000
Subject: Re: DB_DataObject's class generator
References: 1 2  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-16106@lists.php.net to get a copy of this message
"Markus Wolff" <wolff@21st.de> wrote in message news:41B64476.3030609@21st.de... > Torsten Roehr wrote: > > Hi, > > > > is there any specific reason why DO's class generator does not produce > > getter methods for the class properties? Wouldn't this save a lot of work > > for the developer? > > It would, if the developer wants to use those ;-) > > I got no benchmarks at hand, but I've heard numerous times that method > calls are always slower than property assignments, so unless really > needed, you should rely on setting values directly. Hi Markus, first of all thanks for your detailed answer! From what I've read it's perceived as good practice to *not* directly access object properties - even if this might be a bit slower. Also if your internal data structure (e.g. column/property names) change, you don't have to change all your code - just adapt the getter and everything will still work. > > Also, there's theoretical support for overloading (__call() intercepting > all calls to undefined methods) which could be used in a base class for > all DataObjects, so you'll always have getters/setters but they only do > standard property access unless you define a method that does something > special in any of your DataObject classes. Hope this was somehow > understandable. > However, because there are manymanymany bugs with overloading in PHP4, I > wouldn't recommend this - PHP5 is supposed to do better in this > department, but I haven't tried myself. With regards to PHP5 getter methods would be even more appropriate or even required for properties that are protected or private. So what about adding an option to the DO config like generateGetters which defaults to false? I can't imagine I'm the first one to propose this. What do you think - is this worth a feature request? Thanks and best regards, Torsten

« previous php.pear.general (#16106) next »