note 68830 deleted from language.oop5.basic by colder

From: Date: Sun, 19 Aug 2007 23:42:21 +0000
Subject: note 68830 deleted from language.oop5.basic by colder
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-129616@lists.php.net to get a copy of this message
Note Submitter: phpprogrammer at artspad dot net ---- "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.

« previous php.notes (#129616) next »