OK - let's see if I'm starting to get this:
Looking at classes specifically - when I say:
new MyClass();
right there I'm creating an instance of MyClass.
If I say:
$foo = new MyClass();
then I'm creating an instance and then immediately making a copy of it (into $foo).
But if I say:
$foo =& new MyClass();
then there is only one copy of the instance in existence. $foo is the real, accessible "pointer" to it - how I work with it, activate methods in it, etc.
Does that sound right?
What about when I want to return a value from the class - when I'd normally use:
$var = $foo->GetValue($bar);
should I say:
$var =& $foo->GetValue($bar);
or:
$var = $foo->GetValue(&$bar);
or both:
$var =& $foo->GetValue(&$bar);
??
and then there's the method inside the class:
function GetValue($input) {
// stuff
}
I think I understand that if I'm trying to pass the variable by reference, I also need the "&" in the function parameter - thus:
function GetValue(&$input) {
// stuff
}
is that right?
Final question: use of $this->referring to methods (or variables) inside a class. Do I want to pass by reference there?
For instance (this would be calling a method from inside its own class):
$this->var = $this->GetValue($input);
or:
$this->var =& $this->GetValue($input);
or:
$this->var = $this->GetValue(&$input);
what's the best approach in this case? Does it make any difference if I'm referencing into a class-wide attribute ($this->var) vs. just a temporary variable ($var)?
So far I have yet to run into a situation where I need a function or class to alter a variable outside the function/class, but I'm sure I've just been working around it until now, and once I really get the concept I'm going to be able to streamline things nicely.