NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
problem with autocomplete in foreach


Joined: 24 Mar 2014
Posts: 7
Reply with quote
Hi all!
I have a problem in a foreach loop. Autocomplete return me the following error message:
Quote:
1st argument of foreach is recognized as *** class istance but this class is not recognized as supporting iterator interface Failed to identify type of "***" local variable



Code:
    /**
    * put your comment there...
    *
    * @param \Nextop\DataCOREBundle\Document\Flight $flights
    * @return {reportFilling|\Nextop\DataCOREBundle\Document\Flight}
    */
    private function fillFlights($flights){
                               
        $dmn4j = $this->doctrine_neo4j;
        $dm = $this->doctrine_mongodb->getManager();
        $count = 0;
        $ecount = 0;
        $reportFilling = Array();
        foreach($flights as $flight){
            /** @var $flight \Nextop\DataCOREBundle\Document\Flight */
            if(!$this->ndc->flightExists($flight)){
                try{
                   $dm->persist($flight);
                   $dm->flush();
                   $this->rf->airportFilling->ids[] = $flight->getId();//HERE
                   $count++;
                }catch(\Exception $e){
                   $this->rf->airportFilling->errorsCount = ++$ecount;
                }
               
                try{
                   $flightN4j = new Neo4jEntity\Flight();

                }catch(\Exception $e){
                   $this->rf->airportFilling->errorsCount = ++$ecount;
                }

            }
        }
        $this->rf->airportFilling->count = $count;
        $this->dm->clear();
        return $this->rf;     
    }
}


Any idea???
Tnx in advance

Michele
View user's profileFind all posts by devrandomSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
check your \Nextop\DataCOREBundle\Document\Flight class -- does it support iterator interface?

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 24 Mar 2014
Posts: 7
Reply with quote
\Nextop\DataCOREBundle\Document\Flight is a single element in an array ($flights).
I don't understand..you said that $flights array must become a class and implement iterable interface?
View user's profileFind all posts by devrandomSend private message
Guru master

Joined: 24 Jul 2009
Posts: 737
Reply with quote
Have a look at http://www.php.net/manual/en/class.iterator.php and it gives you an example

I think the issue is that PhpED has no way of knowing what your $flights iterates to, so cannot set $flight appropriately. Implementing the interface cures that.
View user's profileFind all posts by plugnplaySend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
Quote:
\Nextop\DataCOREBundle\Document\Flight is a single element in an array ($flights).


If you mean that $flights is an ARRAY of Flight instances, just delare this correctly like below:



What you declared made the IDE thinking it's class, not an array, and therefore it must support iterator to be used in foreach Smile

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 24 Mar 2014
Posts: 7
Reply with quote
dmitri wrote:
What you declared made the IDE thinking it's class, not an array, and therefore it must support iterator to be used in foreach Smile

Tnx Dimitri!
very clear now.

M.
View user's profileFind all posts by devrandomSend private message
problem with autocomplete in foreach
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic