...

View Full Version : Array of Objects



194673
12-24-2007, 11:19 AM
Edit: Code fixed :).

SeeIT Solutions
12-24-2007, 11:28 AM
edited

Mwnciau
12-24-2007, 11:40 AM
I had look around and I could find anything suggesting you could create classes within an array like that, there are 2 workarounds:



$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();

marek_mar
12-24-2007, 11:46 AM
It should be $this->ddArray[$i]->display();.

SeeIT Solutions
12-24-2007, 11:46 AM
post the class code for DropdownItem too.

194673
12-24-2007, 12:01 PM
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.


It should be $this->ddArray[$i]->display();.

Yes it should :). Thanks a lot for the help! What a stupid mistake XD.

Mwnciau
12-24-2007, 12:20 PM
It's the same problem, and it also needs to be less than, not less than or equal to


for ($i = 0; $i < count($this->ddArray); $i++)
{
$this->ddArray[$i]->display(); //bombing out here
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum