Page 1 of 1
is the "&" necessary? $guestbook =& new Gu
Posted: Mon Aug 15, 2005 2:12 pm
by HEMOglobina
While following a tutorial for smarty (
http://smarty.php.net/sampleapp/sampleapp_p2.php) I found the following line of code:
What does the "&" means? Is it needed? I run the code without it ($guestbook = new Guestbook;) and the application behaved just the same...
Thanks a lot,
HEMOglobina
Posted: Mon Aug 15, 2005 2:14 pm
by John Cartwright
it is called reference, it is used when you are refering the object and do not want to create a new copy of the original. This is one automatically in php5.
Posted: Mon Aug 15, 2005 2:17 pm
by feyd
...continuing the thought...
However, I find it a good practice to continue doing "=&" as it's more explicit what's happening, even if the language does it implicitly.
Posted: Mon Aug 15, 2005 2:37 pm
by patrikG
Posted: Mon Aug 15, 2005 4:09 pm
by shiznatix
so how do you re-access your value. i really mean is can you give a good example when you would want to use this?
Posted: Mon Aug 15, 2005 4:51 pm
by feyd
you access it like normal.. The nice part is, you change it to (almost) anything, and the original changes too.