Re: PHP Classes

From: Date: Thu, 12 Dec 2002 01:18:58 +0000
Subject: Re: PHP Classes
References: 1  Groups: php.mirrors 
Request: Send a blank email to php-mirrors+get-14120@lists.php.net to get a copy of this message
If you read up on PHP 5 you will see that this is the major planned change. On Thu, 12 Dec 2002, Erkki Lindpere wrote: > Hi! > > Sorry to bother you, but I didn't find the right contact information on > the php.net website so could you please forward this to the right person. > Thanx. > > I have a request that the behaviour of the "new" operator should be > changed in future PHP versions so that it would *not* return a *copy* by > default, but a *reference*. > > Reasons: > > 1) Currently "new" returns a copy of the object it created. This is not > wanted behaviour (I can't imagine why it would be necessary at all, > anywhere). PHP's class support is weak overall, but I think this is the > biggest problem. > > 2) Of course, it can be overcome by using "& new", BUT programmers WILL > NOT remember that. I was working in a team to create re-usable PHP > components for developing web sites and in the design phase where some > coding was done already I stressed many times that "& new" should be used > to create objects, but even the lead programmer didn't remember that (he > is more of a Java programmer) and I had to fix his code in many places. > > 3) For most users, it is probably not relevant at all how many copies of > one object are there, but if you want to use classes for more than just > containers of variables and functions, it may become very important that > only a single copy of an object exists, especially so when you want to > store an external reference to the object in its constructor. > > For these reasons I think you should seriously consider making the "new" > operator returning a reference by default. Considering how widely PHP is > used and how accessible it is, I think that most PHP programmers will not > read that bit explaining classes & references in the manual or will not > remember to use it. And those who haven't read it have no reason to think > that the new operator makes a copy by default, because that just doesn't > make sense and is not used in any other languages as far as I know. > > Erkki Lindpere > PHP programmer/database designer/OO minded person :) > >

« previous php.mirrors (#14120) next »