PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
HEMOglobina
Forum Newbie
Posts: 6 Joined: Tue Aug 09, 2005 7:23 pm
Post
by HEMOglobina » Mon Aug 15, 2005 2:12 pm
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
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Mon Aug 15, 2005 2:14 pm
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.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Aug 15, 2005 2:17 pm
...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.
patrikG
DevNet Master
Posts: 4235 Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK
Post
by patrikG » Mon Aug 15, 2005 2:37 pm
shiznatix
DevNet Master
Posts: 2745 Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:
Post
by shiznatix » Mon Aug 15, 2005 4:09 pm
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?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Aug 15, 2005 4:51 pm
you access it like normal.. The nice part is, you change it to (almost) anything, and the original changes too.