Jump to content

Use of the & (reference)


kevint

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/189597-use-of-the-reference/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.