Cannot iterate through an object collection.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gasfusion
    New Member
    • Sep 2006
    • 59

    Cannot iterate through an object collection.

    Hey guys.
    I'm building an object collection which will be a part of a Data Access Layer i am currently working on. However, i am having some issues iterating through a collection.
    This is what i've done so far
    1 - Create 'user' class which maps to the MySQL table. The class has basic setters and getters to set/get each field value.
    2 - Created a collection class with simple add/remove/get methods.
    3 - Created user collection class which extends my collection class described above. This user collection class overwrites addItem() method to achieve adding item of type 'user' to my user collection.
    4 - Created collection iterator class which implements Iterator interface and overwrites its basic methods such as rewind/next/current and etc.
    5 - Changed my collection class to implement IteratorAggrega te interface.

    At this point i should be able to use foreach() operator on my collection object but i can't. In fact, it doesn't even go into the foreach loop.

    Here is the source: dowload

    you can see i was testing foreach in the user collection class.

    I appreciate any help i can get on this.
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, Gasfusion.

    foreach only works on public data members when used on a class instance.

    Check out the ArrayObject class.

    Comment

    • gasfusion
      New Member
      • Sep 2006
      • 59

      #3
      I've recoded all classes and got it to work. Have no clue what it was that was wrong.
      Thanks.

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Heya, Gasfusion.

        Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)

        Comment

        Working...