Finally figured out how the heck references works in PHP.
But here's a little problem...
Object myObject;
Object otherObject;
void test1() {
myObject->showData();
}
void test2() {
otherObject->showData();
}
void main() {
myObject = new Object();
otherObject = myObject;
myObject->changeData();
test1();
test2();
myObject- = new Object();
test1();
myObject->changeData();
test2();
}
Let's pretend showData() shows a number and that changeData() changes that number to any random int.
The first time we call test1() and test2() they will display the same number.
The second time we call them they will show different numbers.
How can I reproduce this with PHP?
This code won't work the same way (simplified this time):
$myObject = new Object();
$otherObject = &$myObject;
$myObject->changeData();
$myObject->showData();
$otherObject->showData();
$myObject = new Object();
$myObject->showData();
// I don't want otherObject to point to the new instace!
$otherObject->showData();
// But, ofcourse, it does.
How can I get away with what I'm trying to do? Using a new variable new instead of $myObject works, ofcourse, but when you try to dynamicly add 200 instances, that's a bad idea.