For a php project I use a Collection class to handle my objects and lazyloading in Java-like collections.
Now my object has a collection of emailaddresses for example. So I call the getEmailAddresses() function of the object which calls the mapper to return a collection of emailaddresses.
This works fine, but when I do a foreach loop over my collection it returns valid data with the following error in the end:
Fatal error: Call to a member function create() on a non-object in /foo/bar/Collection.php on line 89
It directs to the following function:
public function current()
{
if ($this->_collection instanceof Iterator)
$key = $this->_collection->key();
else
$key = key($this->_collection);
if ($key === null)
return false;
$item = $this->_collection[$key];
if (!is_object($item)) {
$item = $this->_gateway->create($item);
$this->_collection[$key] = $item;
}
return $item;
}
This line:
$item = $this->_gateway->create($item);
The _gateway is the adapter the collection uses. Which I don’t use and keep it null. Maybe it has something to do with that?
Anybody has some clue? Because everything is functioning as it should, I can read the collectiondata. It’s just the error.
Replace
with
This of course only makes sure the code doesn’t get called if gateway isn’t set, so it doesn’t do anything to $item (which might not be what you want).