Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1001981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:45:39+00:00 2026-05-16T07:45:39+00:00

For a php project I use a Collection class to handle my objects and

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T07:45:40+00:00Added an answer on May 16, 2026 at 7:45 am

    Replace

    if (!is_object($item))
    

    with

    if (!is_object($item) && !is_null($this->_gateway))
    

    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).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've started a php project, it will use cakePhp. I saw that cakePhp has
I am working on a PHP project. There, I often use following syntax to
Hi I am doing my project in PHP.In this when the use r doesnt
I've a project, with various subdirs that make use of a functions.php file located
Right now i have a PHP project and i track all changes in code
Right now, I am working on a web project in PHP and for the
I use smarty template language in my php project. It works great except I'm
I have a php project with unit tests included. I use Netbeans for development
If I'm writing a PHP project and decide to use a third-party ORM or
I use symfony's ProjectConfiguration.class.php for configuring doctrine's connection: public function configureDoctrineConnectionCertby(Doctrine_Connection $conn) { $conn->setListener(new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.