note 68830 added to language.oop5.basic

From: Date: Sat, 12 Aug 2006 11:29:37 +0000
Subject: note 68830 added to language.oop5.basic
Groups: php.notes 
Request: Send a blank email to php-notes+get-115824@lists.php.net to get a copy of this message
"Once again, I reiterate, there's no need to overwrite variables and open this can of worms: just make a new variable and be done with it. As long as you don't overwrite variables, it doesn't matter whether or not you use references or assignments (unless you're planning for PHP4 compatibility). " Always suspect advice that disregards nuanced functionality available to you. The difference between getting a reference versus a copy is subtle but powerful. It really only became highly relevant to me when I was working in Flash with XML. The nodes from the xml structure were returned as references. So getting a node and changing its value didn't just change the node variable I had, it updated the node within the xml document. Had I only gotten a copy I would have had to have routines for removing and inserting the node in the overall structure. The moral of this story is that there are times when overwriting variables in a reference is actually very practical and a sign of evovled coding. Also, there's the old trick of passing an object reference to a function as a parameter so that you can change its properties and not have to return anything. This is particularly useful if you pass more than one object reference to the function, since a function can only ever return one value. There is a caveat in using references in that so long as one variable within scope is holding a copy of the reference the object will remain in memory. Please take the time to really learn virtue of references versus copies and decide for yourself whether its a tool that can help you. ---- Server IP: 64.71.164.2 Probable Submitter: 71.117.64.209 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.basic.php Edit -- https://master.php.net/note/edit/68830 Del: integrated -- https://master.php.net/note/delete/68830/integrated Del: useless -- https://master.php.net/note/delete/68830/useless Del: bad code -- https://master.php.net/note/delete/68830/bad+code Del: spam -- https://master.php.net/note/delete/68830/spam Del: non-english -- https://master.php.net/note/delete/68830/non-english Del: in docs -- https://master.php.net/note/delete/68830/in+docs Del: other reasons-- https://master.php.net/note/delete/68830 Reject -- https://master.php.net/note/reject/68830 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#115824) next »