I am porting C# code to PHP.
However, it seems like PHP ignores the array references. The code below gives out the last element 3 times. How can I fix this?
class Participants
{
public $name;
public $country;
public $town;
}
class Test
{
public function __construct()
{
$this->List = array(new Participants());
}
public function test()
{
$p = new Participants();
$p->name = "Harry";
$p->town = "Washington";
$p->country = "USA";
$List[0] = $p;
$p->name = "Janette";
$p->town = "Amsterdam";
$p->country = "Netherlands";
$List[1] = $p;
$p->name = "Piotr";
$p->town = "Moscow";
$p->country = "Russia";
$List[2] = $p;
echo $List[0]->name;
echo $List[1]->name;
echo $List[2]->name;
// this unfortunately ignores the index and echoes 3 times the last element.
}
}//end Test Class