I am trying to learn object-oriented programming, but here I am. I can't get basic things working.
How do I put "object array" inside another class/object?
Here is code:
class Block
{
private $landscapeName, $landscapeColor, $landscapeImage;
private $buildingName, $buildingImage;
public function __construct($db=NULL, $x=0, $y=0)
{
}
public function getLandscapeImage()
{
return "bgGrass.png";
}
}
class Map
{
private $block;
public function __construct($db=NULL)
{
for ($i=0;$i<3;$i++)
for ($j=0;$j<3;$j++)
$block[$i][$j] = new Block($db, $i, $j);
//This works
print $block[0][0]->getLandscapeImage();
}
public function build($db, $x, $y)
{
$block[$x][$y]->build();
}
public function giveArea($x = 0, $y = 0)
{
//This works not
$block[0][0]->getLandscapeImage();
}
}
$wholeMap = new Map();
$wholeMap->giveArea();
When $wholeMap->giveArea(); is called it gives "Fatal error: Call to a member function getLandscapeImage() on a non-object".
What am I doing wrong? :/