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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.