RE: [PHP4BETA] OOP issue

From: Date: Tue, 16 Nov 1999 10:36:10 +0000
Subject: RE: [PHP4BETA] OOP issue
References: 1  Groups: php.version4 
Request: Send a blank email to php-version4+get-6285@lists.php.net to get a copy of this message
> -----Original Message----- > From: cschneid@relog.ch [mailto:cschneid@relog.ch] > Sent: Monday, November 15, 1999 01:55 PM > To: php4beta@lists.php.net > Cc: Christian A. Weber > Subject: [PHP4BETA] OOP issue > > > After seeing Andi Gutmans' mail about changing $a['x'] to $a{'x'} to > clean up the language I figured it would make sense to discuss some more > points on how to enhance the language. The downside is that these > changes break existing code but on the other hand PHP4 might be the last > chance to fix things. > > I want to propose changing assignment of objects from copy to reference, > i.e. change the semantics of > $a = $some_object; to what's currently done by $a = &$some_object; > and to introduce > $a = clone($some_object); to what's currently done by $a = $some_object. > My limited OOP experience tells me that 95% of the time one wants a > reference, not a copy. Yes. I was shcoked and horrified to find a copy was made each time; the same for function MyFunc($myObject) { which takes a COPY unless & is used. This scared me too, and is no doubt the cause of much broken code. > While having the reference operator around is inelegant but working I > ran into severe problems trying to iterate through an associative array > containing objects: each() and friends always return copies of the > contained objects. > The best solution I found was doing something like > for (reset($b); $object = &$b[key($b)]; next($b)) > > While copying may work most of the time even when a reference would be > more appropriate it adds unnecessary overhead to the program. I beg for this change. Sam

« previous php.version4 (#6285) next »