Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:18948 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 75365 invoked by uid 1010); 15 Sep 2005 04:29:36 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 75349 invoked from network); 15 Sep 2005 04:29:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Sep 2005 04:29:36 -0000 X-Host-Fingerprint: 220.245.213.234 220-245-213-234-act.tpgi.com.au Received: from ([220.245.213.234:28488] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id D5/7D-41173-FA8F8234 for ; Thu, 15 Sep 2005 00:29:35 -0400 Message-ID: To: internals@lists.php.net Date: Thu, 15 Sep 2005 14:29:24 +1000 User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 References: <43276022.6020702@encode.net.au> <7C.1C.41173.4D828234@pb1.pair.com> <63.BA.41173.BB6E8234@pb1.pair.com> <4328EFC1.3030500@lerdorf.com> In-Reply-To: <4328EFC1.3030500@lerdorf.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 220.245.213.234 Subject: Re: [PHP-DEV] Reference handling change and PHP 4.4.0 From: colin@encode.net.au (Colin Tucker) Rasmus Lerdorf wrote: > So while the tone of some of these messages may not be great, > often the suggestion that the code in question isn't very good is > accurate. Rasmus, I think where some of the concern and confusion lies is with those of us who have been doing, or at least attempting, some "heavy" OOP with PHP4. Now, PHP4 may not be the most ideal platform for OOP (hence the changes PHP5 brings), but nevertheless it *is* there, it is available to use, and despite it's shortcomings, use it we did. Many of us who did some crazy OOP in PHP4 have used references heavily because, like in PHP5, we wanted to avoid making copies of objects everywhere. Hence, a lot of code returns by reference and assigns by reference. At the time, I certainly didn't think I was writing "bad" code - it seemed to make sense, and PHP4 happily ran it as expected without error or complaint. Code like this, for example: function &getProcessor() { return $this->processor->getInstance(); } ...where the processor attribute is a dynamically-configured object which may generate a different object instance (from getInstance() call) depending on it's configuration. Now in 4.4, this of course generates a notice, and has to be changed to: function &getProcessor() { $instance =& $this->processor->getInstance(); return $instance; } ...which to me just seems like a waste of space. This raises other questions, for example, what if we're trying to return something by reference and encounter a problem with returning that something? For example, take some sort of collection or list class: function &at($index=NULL) { if ($this->hasIndex($index)) { return $this->elements[$index]; } return NULL; } ...you want to grab an element at the specified index by reference if it's an object. The above code used to work fine, but now of course it generates a notice, and needs to be changed to something like: function &at($index=NULL) { $element = NULL; if ($this->hasIndex($index)) { $element =& $this->elements[$index]; } return $element; } These things by themselves are not a big deal, but many of us have these "little" issues happening throughout our code, resulting in hundreds upon hundreds of notices per page request. Perhaps according to the true nature of references these examples were not the ideal way to code, but I don't consider it "bad code", and it was certainly legal and fully-functional code for some time now. Call it awful if you like, but it certainly made sense to me at the time. Regards, Colin.