Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Dec 2006
    Posts
    166
    Thanks
    9
    Thanked 4 Times in 4 Posts

    Array of Objects

    Edit: Code fixed .
    Last edited by 194673; 12-24-2007 at 01:23 PM.

  • #2
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts
    edited
    Last edited by SeeIT Solutions; 12-24-2007 at 12:30 PM. Reason: didn't read properly...

  • #3
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    I had look around and I could find anything suggesting you could create classes within an array like that, there are 2 workarounds:

    PHP Code:
    $array[] = new DropdownItem("test","test.php");
    $array[] = new DropdownItem("test2","test2.php")
    $home = new NavigationItem("Home""index.php"$array);
    $home->display();

    // or 

    $home = new NavigationItem("Home""index.php", array("test","test.php""test2","test2.php")));  // then declare the classes in the constructor
    $home->display(); 

  • #4
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    It should be $this->ddArray[$i]->display();.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • Users who have thanked marek_mar for this post:

    194673 (12-24-2007)

  • #5
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts
    post the class code for DropdownItem too.

  • #6
    Regular Coder
    Join Date
    Dec 2006
    Posts
    166
    Thanks
    9
    Thanked 4 Times in 4 Posts
    Quote Originally Posted by Mwnciau View Post
    I had look around and I could find anything suggesting you could create classes within an array like that
    Why couldn't you instantiate an object within an array? It's basically just creating the object without a reference, and since I don't need to use it anywhere else, I don't really need a variable to store it.

    Quote Originally Posted by marek_mar View Post
    It should be $this->ddArray[$i]->display();.
    Yes it should . Thanks a lot for the help! What a stupid mistake XD.

  • #7
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    It's the same problem, and it also needs to be less than, not less than or equal to

    PHP Code:
    for ($i 0$i count($this->ddArray); $i++)
            {
                
    $this->ddArray[$i]->display(); //bombing out here
            



  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •