In PHP 5+, objects are passed by reference. This has got me into trouble in the past when I've tried to make arrays of objects. For example, I once wrote something like the following code, thinking that I'd get an array of distinct objects. However, this is wrong. This code will create an array of multiple references to the same object.
notice that the value at each index in the array is the same. That is because the array is just 3 references to the same object, but we change the property of this object every time the for loop runs. This isn't very useful. Instead, I've changed the code below so that it will create an array with three distinct references to three distinct objects. (if you're having a hard time understanding references, think of this as an array of objects, and that this is just the syntax you have to use.)
In PHP 5+, objects are passed by reference. This has got me into trouble in the past when I've tried to make arrays of objects. For example, I once wrote something like the following code, thinking that I'd get an array of distinct objects. However, this is wrong. This code will create an array of multiple references to the same object.0