kevint Posted January 24, 2010 Share Posted January 24, 2010 I haven't been writing PHP all that long; I like to look at a lot of code to learn from it. So, I'm noticing lots of use of the "&" thing to pass references, in places where I can't understand the need for it. For example, this (from an example snip of code for a PEAR extension): <?php $r =& new XML_RSS("test.rss"); ?> Why is the & needed here? How does anything benefit from this? I understand that the & can be used to create references, but I am not sure why this is ever really a useful thing to do (rather than just using the variable itself, instead of the reference). Can someone possibly share with me how, and why, they tend to use this feature? In general, that is; and specifically, in the example above, does anyone know why it was done this way (like it also is in so much other code that I see)? Thanks in advance for any replies; cheers. Quote Link to comment https://forums.phpfreaks.com/topic/189597-use-of-the-reference/ Share on other sites More sharing options...
Daniel0 Posted January 24, 2010 Share Posted January 24, 2010 It isn't needed. In fact it's discouraged as of PHP 5. Quote Link to comment https://forums.phpfreaks.com/topic/189597-use-of-the-reference/#findComment-1000808 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.