references

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
rg34
Forum Newbie
Posts: 4
Joined: Sun May 01, 2005 1:44 pm

references

Post 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.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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)
rg34
Forum Newbie
Posts: 4
Joined: Sun May 01, 2005 1:44 pm

Post 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.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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...
rg34
Forum Newbie
Posts: 4
Joined: Sun May 01, 2005 1:44 pm

Post 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.
The Monkey
Forum Contributor
Posts: 168
Joined: Tue Mar 09, 2004 9:05 am
Location: Arkansas, USA

Post by The Monkey »

Post Reply