Variables: References
Date: 03/21/07
(PHP Community) Keywords: no keywords
I'm having a stupid day.
I have a class. That class has an array variable. I want to create an instance of another class into an object, cache it in the array and return a reference to that object.
e.g.
class Thing1 {
var $thing2s;
function Thing1()
{
$this->thing2s = array();
}
function getThing2($argument)
{
if (!array_key_exists($argument, $this->thing2s)) {
$this->things2[$argument] = new Thing2($argument);
}
return $this->things2[$argument];
}
}
Now I'm reasonably sure that the above is putting a Thing2 instance into the $things2 array, and returning a COPY. I want to return a reference. Which I would do with
return &$this->things2[$argument];
Right?
Source: http://community.livejournal.com/php/554973.html