I'm still working on understanding when to use references and when not to. The basic gist I'm getting from what I'm reading is that they should be used when doing object-oriented programming that involves passing objects around, to make an application's behavior more predictable. That more or less right?
At present I'm only using the reference operator in one situation, which is creating class instances:
$object = &new myClass;
I'm told I should do this because if I don't, I'll be creating an instance and then making a copy of it, which is wasteful of resources. So I do this universally. I think I understand this part.
I'm NOT using references when passing things into or out of my class instances. So I do:
$object->setParameter($var);
and
$result = $object->getValue();
and within the class
function foo($var_1, $var_2) {
$this->value = $var_1;
}
No reference operators anywhere else.
Is this a good idea? Is it better to use references in some of these cases?
I should add that I'm not yet passing complete objects around much - I don't really "get it" - mostly I just create objects and use them for particular purposes, and not pass one into another. But I'm going to try to learn to do - as soon as I figure out why I'd want to.
If anyone can point me to some understandable examples of well-written object-oriented PHP I'd appreciate that as well.
Thanks,
Bob