Re: DB_DataObject: what am I missing?

From: Date: Sun, 23 Jan 2005 21:35:13 +0000
Subject: Re: DB_DataObject: what am I missing?
References: 1 2 3 4 5  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-17115@lists.php.net to get a copy of this message
On Sun, 23 Jan 2005 15:05:22 -0600, Larry Garfield <larry@garfieldtech.com> wrote: > Justin Patrin wrote: > > >>The current bug aside, why are people so against overloading? Without > >>the accessor/modifier methods, you have to access the data directly, > >>which breaks encapsulation. (Yes, I happen to like OO concepts. <g>) > >>You could just write them yourself (as you would have to in Java or many > >>other languages), but then you're losing half of the point of using DBDO > >>in the first place. > > > > Because it breaks pass-by-reference. You have to use > > call-time-pass-by-reference to get around it, and that's deprecated > > and causes warnings. Getters and setters can be nice, but IMHO > > overloading should not be used in PHP4 as it breaks things. It should > > have been kept for PHP5 which does not have the same issues. > > By call-time-pass-by-reference, I presume you mean: > > $a =& new b(); > $c = d(&$e); > > Coming from a C/C++ background, I'm used to that sort of syntax. I > understand PHP5's object model is much more Java-ish (pass by copy of > reference, so effectively all objects are pass by reference), so that > clears up some things but messes others. Is that why the syntax is > deprecated? $a =& new b(); is still fully ok. It's deprecated because you're supposed to put the declaration in the function call. function a(&$b) { $b['a'] = 1; } a($c); This makes much more sense. But when you turn on overloading, PHP4 doesn't honor this declaration any more. To get it back you have to use: $a(&$c); which is ugly and easy to screw up. And also breaks any existing code. > > For those of us stuck with web hosts who are still on PHP4, then, your > suggestion would be to just skip getters/setters and write > unencapsulated until they wise up and get PHP5? I'm not particularly > fond of that idea. :-) > Well, that's how I'm using it at the moment. But you could also just add real setters/getters for your DOs with the generator patch mentioned. IMHO this is a much better solution that using overloading in PHP4 as *it is broken*. -- Justin Patrin

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