Page 1 of 1

references

Posted: Sun May 01, 2005 1:46 pm
by rg34
Hi,

I do not understand when to use references and when to not use references. I have looked at a ton of information on the web, and I just don't understand it...

I use references when passing arrays... but other than that, I do not understand when to use them.

Thank you.

Posted: Sun May 01, 2005 2:06 pm
by timvw
it is usefull i you have "large" datastructures that need to be passed around... because otherwise you need to copy them... certainly with recursive functions thiis can become a major partystopper ;)

and then with php4, if you have a function that manipulates an object (passed via a parameter), you will be surprised that a copy was manipulated... so in that case it is also required to use a reference (instead of a copy by value)

Posted: Sun May 01, 2005 2:18 pm
by rg34
so would you always use references then? even when making a variable equal something? this is because I use OO and am passing multiple arrays through function arguments. not to mention, different pages.

Posted: Sun May 01, 2005 2:22 pm
by timvw
i wouldn't always use references. only where i think they are useful.

for example: java copies all parameters that are a basic type by value, and all objects by reference...

Posted: Sun May 01, 2005 2:23 pm
by rg34
it's really confusing to understand.... i've looked at a lot of literature about PHP references, and I don't understand when it's "useful"

Do you have any links that have specific examples?

Thank you.

Posted: Sun May 01, 2005 2:29 pm
by The Monkey